Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

30
test/fixtures/module-hooks/add-hook.js vendored Normal file
View File

@ -0,0 +1,30 @@
'use strict';
const { fileURLToPath } = require('url');
const { registerHooks } = require('module');
// This is a simplified version of the pirates package API to
// check that a similar API can be built on top of the public
// hooks.
function addHook(hook, options) {
function load(url, context, nextLoad) {
const result = nextLoad(url, context);
const index = url.lastIndexOf('.');
const ext = url.slice(index);
if (!options.exts.includes(ext)) {
return result;
}
const filename = fileURLToPath(url);
if (!options.matcher(filename)) {
return result;
}
return { ...result, source: hook(result.source.toString(), filename) }
}
const registered = registerHooks({ load });
return function revert() {
registered.deregister();
};
}
module.exports = { addHook };

20
test/fixtures/module-hooks/get-stats.js vendored Normal file
View File

@ -0,0 +1,20 @@
'use strict';
const path = require('path');
// Adapted from https://github.com/watson/module-details-from-path/blob/master/index.js
// used by require-in-the-middle to check the logic is still compatible with our new hooks.
exports.getStats = function getStats(filepath) {
const segments = filepath.split(path.sep);
const index = segments.lastIndexOf('node_modules');
if (index === -1) return {};
if (!segments[index + 1]) return {};
const scoped = segments[index + 1][0] === '@';
const name = scoped ? segments[index + 1] + '/' + segments[index + 2] : segments[index + 1];
const offset = scoped ? 3 : 2;
return {
name: name,
basedir: segments.slice(0, index + offset).join(path.sep),
path: segments.slice(index + offset).join(path.sep)
}
};

View File

@ -0,0 +1,4 @@
'use strict';
exports.require = require;
exports.import = (id) => import(id);

View File

@ -0,0 +1,3 @@
const { UserAccount, UserType } = require('./user.ts');
const account: typeof UserAccount = new UserAccount('john', 100, UserType.Admin);
console.log(account);

View File

@ -0,0 +1,4 @@
import { UserAccount, UserType } from './user.ts';
import { log } from 'node:console';
const account: UserAccount = new UserAccount('john', 100, UserType.Admin);
log(account);

View File

@ -0,0 +1 @@
export const $key = 'bar-esm';

View File

@ -0,0 +1,6 @@
{
"name": "bar-esm",
"main": "bar-esm.js",
"type": "module",
"version": "1.0.0"
}

3
test/fixtures/module-hooks/node_modules/bar/bar.js generated vendored Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
$key: 'bar'
};

View File

@ -0,0 +1,6 @@
{
"name": "bar",
"main": "bar.js",
"version": "1.0.0"
}

View File

@ -0,0 +1 @@
export const $key = 'foo-esm';

View File

@ -0,0 +1,7 @@
{
"name": "foo-esm",
"type": "module",
"main": "foo-esm.js",
"version": "1.0.0"
}

3
test/fixtures/module-hooks/node_modules/foo/foo.js generated vendored Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
$key: 'foo'
};

View File

@ -0,0 +1,6 @@
{
"name": "foo",
"main": "foo.js",
"version": "1.0.0"
}

View File

@ -0,0 +1 @@
exports.exports_for_test = 'redirected assert'

View File

@ -0,0 +1 @@
export const exports_for_test = 'redirected fs';

View File

@ -0,0 +1 @@
exports.exports_for_test = 'redirected zlib';

View File

@ -0,0 +1,4 @@
'use strict';
const { registerHooks } = require('node:module');
registerHooks(require('./typescript-transpiler'));

View File

@ -0,0 +1,71 @@
'use strict';
const ts = require('../snapshot/typescript');
const extensions = {
'.cts': 'commonjs-typescript',
'.mts': 'module-typescript',
'.ts': 'typescript',
};
const output = {
'commonjs-typescript': {
options: { module: ts.ModuleKind.CommonJS },
format: 'commonjs',
},
'module-typescript': {
options: { module: ts.ModuleKind.ESNext },
format: 'module',
},
'typescript': {
options: { module: ts.ModuleKind.NodeNext },
format: 'commonjs',
},
};
function resolve(specifier, context, nextResolve) {
const resolved = nextResolve(specifier, context);
const index = resolved.url.lastIndexOf('.');
if (index === -1) {
return resolved;
}
const ext = resolved.url.slice(index);
const supportedFormat = extensions[ext];
if (!supportedFormat) {
return resolved;
}
const result = {
...resolved,
format: supportedFormat,
};
return result;
}
let decoder;
function load(url, context, nextLoad) {
const loadResult = nextLoad(url, context);
const { source, format } = loadResult;
if (!format || !format.includes('typescript')) {
return { format, source };
}
let str = source;
if (typeof str !== 'string') {
decoder ??= new TextDecoder();
str = decoder.decode(source);
}
const transpiled = ts.transpileModule(str, {
compilerOptions: output[format].options
});
const result = {
...loadResult,
format: output[format].format,
source: transpiled.outputText,
};
return result;
}
exports.load = load;
exports.resolve = resolve;

18
test/fixtures/module-hooks/user.ts vendored Normal file
View File

@ -0,0 +1,18 @@
enum UserType {
Staff,
Admin,
};
class UserAccount {
name: string;
id: number;
type: UserType;
constructor(name: string, id: number, type: UserType) {
this.name = name;
this.id = id;
this.type = type;
}
}
export { UserAccount, UserType };