@expo/require-utils 55.0.1 → 55.0.3-canary-20260424-7bedc9d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/codeframe.d.ts +1 -1
- package/build/codeframe.js +17 -15
- package/build/codeframe.js.map +1 -1
- package/build/index.d.ts +2 -0
- package/build/index.js +22 -0
- package/build/index.js.map +1 -1
- package/build/load.d.ts +2 -1
- package/build/load.js +74 -27
- package/build/load.js.map +1 -1
- package/build/resolve.d.ts +10 -0
- package/build/resolve.js +91 -0
- package/build/resolve.js.map +1 -0
- package/build/resolveGlobal.d.ts +7 -0
- package/build/resolveGlobal.js +162 -0
- package/build/resolveGlobal.js.map +1 -0
- package/build/transform.d.ts +1 -0
- package/build/transform.js +32 -0
- package/build/transform.js.map +1 -0
- package/package.json +12 -9
package/build/codeframe.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ import type { Diagnostic } from 'typescript';
|
|
|
2
2
|
export declare function formatDiagnostic(diagnostic: Diagnostic | undefined): (SyntaxError & {
|
|
3
3
|
codeFrame: string;
|
|
4
4
|
}) | null;
|
|
5
|
-
export declare function annotateError(code: string, filename: string, error: Error): (Error & {
|
|
5
|
+
export declare function annotateError(code: string | null, filename: string, error: Error): (Error & {
|
|
6
6
|
codeFrame: string;
|
|
7
7
|
}) | null;
|
package/build/codeframe.js
CHANGED
|
@@ -66,21 +66,23 @@ function annotateError(code, filename, error) {
|
|
|
66
66
|
if (typeof error !== 'object' || error == null) {
|
|
67
67
|
return null;
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
69
|
+
if (code) {
|
|
70
|
+
const loc = errorToLoc(filename, error);
|
|
71
|
+
if (loc) {
|
|
72
|
+
const {
|
|
73
|
+
codeFrameColumns
|
|
74
|
+
} = require('@babel/code-frame');
|
|
75
|
+
const codeFrame = codeFrameColumns(code, {
|
|
76
|
+
start: loc
|
|
77
|
+
}, {
|
|
78
|
+
highlightCode: true
|
|
79
|
+
});
|
|
80
|
+
const annotatedError = error;
|
|
81
|
+
annotatedError.codeFrame = codeFrame;
|
|
82
|
+
annotatedError.message += `\n${codeFrame}`;
|
|
83
|
+
delete annotatedError.stack;
|
|
84
|
+
return annotatedError;
|
|
85
|
+
}
|
|
84
86
|
}
|
|
85
87
|
return null;
|
|
86
88
|
}
|
package/build/codeframe.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codeframe.js","names":["_nodeUrl","data","_interopRequireDefault","require","e","__esModule","default","errorToLoc","filename","error","name","stack","slice","length","message","trace","match","url","pathToFileURL","href","line","Number","isSafeInteger","column","undefined","formatDiagnostic","diagnostic","start","file","messageText","codeFrameColumns","character","getLineAndCharacterOfPosition","loc","codeFrame","getText","highlightCode","annotatedError","SyntaxError","annotateError","code"],"sources":["../src/codeframe.ts"],"sourcesContent":["import url from 'node:url';\nimport type { Diagnostic } from 'typescript';\n\nfunction errorToLoc(filename: string, error: Error) {\n if (error.name === 'ReferenceError' || error.name === 'SyntaxError') {\n let stack = `${error.stack || ''}`;\n stack = stack.slice(error.name.length + 2 /* '${name}: ' prefix */);\n stack = stack.slice(error.message.length);\n const trace = stack.match(/at ([^\\n]+):(\\d+):(\\d+)/m);\n if (url.pathToFileURL(filename).href === trace?.[1]) {\n const line = Number(trace[2]);\n return Number.isSafeInteger(line) ? { line, column: Number(trace[3]) || undefined } : null;\n }\n }\n return null;\n}\n\nexport function formatDiagnostic(diagnostic: Diagnostic | undefined) {\n if (!diagnostic) {\n return null;\n }\n const { start, file, messageText } = diagnostic;\n if (file && messageText && start != null) {\n const { codeFrameColumns }: typeof import('@babel/code-frame') = require('@babel/code-frame');\n const { line, character } = file.getLineAndCharacterOfPosition(start);\n const loc = { line: line + 1, column: character + 1 };\n const codeFrame = codeFrameColumns(file.getText(), { start: loc }, { highlightCode: true });\n const annotatedError = new SyntaxError(`${messageText}\\n${codeFrame}`) as SyntaxError & {\n codeFrame: string;\n };\n annotatedError.codeFrame = codeFrame;\n delete annotatedError.stack;\n return annotatedError;\n }\n return null;\n}\n\nexport function annotateError(code: string, filename: string, error: Error) {\n if (typeof error !== 'object' || error == null) {\n return null;\n }\n const loc = errorToLoc(filename, error);\n
|
|
1
|
+
{"version":3,"file":"codeframe.js","names":["_nodeUrl","data","_interopRequireDefault","require","e","__esModule","default","errorToLoc","filename","error","name","stack","slice","length","message","trace","match","url","pathToFileURL","href","line","Number","isSafeInteger","column","undefined","formatDiagnostic","diagnostic","start","file","messageText","codeFrameColumns","character","getLineAndCharacterOfPosition","loc","codeFrame","getText","highlightCode","annotatedError","SyntaxError","annotateError","code"],"sources":["../src/codeframe.ts"],"sourcesContent":["import url from 'node:url';\nimport type { Diagnostic } from 'typescript';\n\nfunction errorToLoc(filename: string, error: Error) {\n if (error.name === 'ReferenceError' || error.name === 'SyntaxError') {\n let stack = `${error.stack || ''}`;\n stack = stack.slice(error.name.length + 2 /* '${name}: ' prefix */);\n stack = stack.slice(error.message.length);\n const trace = stack.match(/at ([^\\n]+):(\\d+):(\\d+)/m);\n if (url.pathToFileURL(filename).href === trace?.[1]) {\n const line = Number(trace[2]);\n return Number.isSafeInteger(line) ? { line, column: Number(trace[3]) || undefined } : null;\n }\n }\n return null;\n}\n\nexport function formatDiagnostic(diagnostic: Diagnostic | undefined) {\n if (!diagnostic) {\n return null;\n }\n const { start, file, messageText } = diagnostic;\n if (file && messageText && start != null) {\n const { codeFrameColumns }: typeof import('@babel/code-frame') = require('@babel/code-frame');\n const { line, character } = file.getLineAndCharacterOfPosition(start);\n const loc = { line: line + 1, column: character + 1 };\n const codeFrame = codeFrameColumns(file.getText(), { start: loc }, { highlightCode: true });\n const annotatedError = new SyntaxError(`${messageText}\\n${codeFrame}`) as SyntaxError & {\n codeFrame: string;\n };\n annotatedError.codeFrame = codeFrame;\n delete annotatedError.stack;\n return annotatedError;\n }\n return null;\n}\n\nexport function annotateError(code: string | null, filename: string, error: Error) {\n if (typeof error !== 'object' || error == null) {\n return null;\n }\n if (code) {\n const loc = errorToLoc(filename, error);\n if (loc) {\n const { codeFrameColumns }: typeof import('@babel/code-frame') = require('@babel/code-frame');\n const codeFrame = codeFrameColumns(code, { start: loc }, { highlightCode: true });\n const annotatedError = error as Error & { codeFrame: string };\n annotatedError.codeFrame = codeFrame;\n annotatedError.message += `\\n${codeFrame}`;\n delete annotatedError.stack;\n return annotatedError;\n }\n }\n return null;\n}\n"],"mappings":";;;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA2B,SAAAC,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAG3B,SAASG,UAAUA,CAACC,QAAgB,EAAEC,KAAY,EAAE;EAClD,IAAIA,KAAK,CAACC,IAAI,KAAK,gBAAgB,IAAID,KAAK,CAACC,IAAI,KAAK,aAAa,EAAE;IACnE,IAAIC,KAAK,GAAG,GAAGF,KAAK,CAACE,KAAK,IAAI,EAAE,EAAE;IAClCA,KAAK,GAAGA,KAAK,CAACC,KAAK,CAACH,KAAK,CAACC,IAAI,CAACG,MAAM,GAAG,CAAC,CAAC,wBAAwB,CAAC;IACnEF,KAAK,GAAGA,KAAK,CAACC,KAAK,CAACH,KAAK,CAACK,OAAO,CAACD,MAAM,CAAC;IACzC,MAAME,KAAK,GAAGJ,KAAK,CAACK,KAAK,CAAC,0BAA0B,CAAC;IACrD,IAAIC,kBAAG,CAACC,aAAa,CAACV,QAAQ,CAAC,CAACW,IAAI,KAAKJ,KAAK,GAAG,CAAC,C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AAQ,IAAIA,KAAK,IAAI,IAAI,EAAE;IAC9C,OAAO,IAAI;EACb;EACA,IAAI+B,IAAI,EAAE;IACR,MAAMP,GAAG,GAAG1B,UAAU,CAACC,QAAQ,EAAEC,KAAK,CAAC;IACvC,IAAIwB,GAAG,EAAE;MACP,MAAM;QAAEH;MAAqD,CAAC,GAAG3B,OAAO,CAAC,mBAAmB,CAAC;MAC7F,MAAM+B,SAAS,GAAGJ,gBAAgB,CAACU,IAAI,EAAE;QAAEb,KAAK,EAAEM;MAAI,CAAC,EAAE;QAAEG,aAAa,EAAE;MAAK,CAAC,CAAC;MACjF,MAAMC,cAAc,GAAG5B,KAAsC;MAC7D4B,cAAc,CAACH,SAAS,GAAGA,SAAS;MACpCG,cAAc,CAACvB,OAAO,IAAI,KAAKoB,SAAS,EAAE;MAC1C,OAAOG,cAAc,CAAC1B,KAAK;MAC3B,OAAO0B,cAAc;IACvB;EACF;EACA,OAAO,IAAI;AACb","ignoreList":[]}
|
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -14,4 +14,26 @@ Object.keys(_load).forEach(function (key) {
|
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
});
|
|
17
|
+
var _resolve = require("./resolve");
|
|
18
|
+
Object.keys(_resolve).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _resolve[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _resolve[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _resolveGlobal = require("./resolveGlobal");
|
|
29
|
+
Object.keys(_resolveGlobal).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _resolveGlobal[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _resolveGlobal[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
17
39
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_load","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["../src/index.ts"],"sourcesContent":["export * from './load';\n"],"mappings":";;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,KAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,KAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,KAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_load","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_resolve","_resolveGlobal"],"sources":["../src/index.ts"],"sourcesContent":["export * from './load';\nexport * from './resolve';\nexport * from './resolveGlobal';\n"],"mappings":";;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,KAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,KAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,KAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,QAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,QAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,QAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,QAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,cAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,cAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,cAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,cAAA,CAAAN,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
package/build/load.d.ts
CHANGED
|
@@ -8,10 +8,11 @@ declare global {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
+
type Format = 'commonjs' | 'module' | 'module-typescript' | 'commonjs-typescript' | 'typescript';
|
|
11
12
|
export interface ModuleOptions {
|
|
12
13
|
paths?: string[];
|
|
13
14
|
}
|
|
14
|
-
declare function evalModule(code: string, filename: string, opts?: ModuleOptions): any;
|
|
15
|
+
declare function evalModule(code: string, filename: string, opts?: ModuleOptions, format?: Format): any;
|
|
15
16
|
declare function loadModule(filename: string): Promise<any>;
|
|
16
17
|
/** Require module or evaluate with TypeScript
|
|
17
18
|
* NOTE: Requiring ESM has been added in all LTS versions (Node 20.19+, 22.12+, 24).
|
package/build/load.js
CHANGED
|
@@ -41,9 +41,15 @@ function _codeframe() {
|
|
|
41
41
|
};
|
|
42
42
|
return data;
|
|
43
43
|
}
|
|
44
|
+
function _transform() {
|
|
45
|
+
const data = require("./transform");
|
|
46
|
+
_transform = function () {
|
|
47
|
+
return data;
|
|
48
|
+
};
|
|
49
|
+
return data;
|
|
50
|
+
}
|
|
44
51
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
45
|
-
function
|
|
46
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
52
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
47
53
|
let _ts;
|
|
48
54
|
function loadTypescript() {
|
|
49
55
|
if (_ts === undefined) {
|
|
@@ -65,65 +71,88 @@ const tsExtensionMapping = {
|
|
|
65
71
|
'.cts': '.cjs',
|
|
66
72
|
'.mts': '.mjs'
|
|
67
73
|
};
|
|
68
|
-
function
|
|
74
|
+
function maybeReadFileSync(filename) {
|
|
75
|
+
try {
|
|
76
|
+
return _nodeFs().default.readFileSync(filename, 'utf8');
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (error.code === 'ENOENT') {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function toFormat(filename, isLegacy) {
|
|
69
85
|
if (filename.endsWith('.cjs')) {
|
|
70
86
|
return 'commonjs';
|
|
71
87
|
} else if (filename.endsWith('.mjs')) {
|
|
72
88
|
return 'module';
|
|
73
89
|
} else if (filename.endsWith('.js')) {
|
|
74
|
-
return
|
|
90
|
+
return isLegacy ? 'commonjs' : null;
|
|
75
91
|
} else if (filename.endsWith('.mts')) {
|
|
76
92
|
return 'module-typescript';
|
|
77
93
|
} else if (filename.endsWith('.cts')) {
|
|
78
94
|
return 'commonjs-typescript';
|
|
79
95
|
} else if (filename.endsWith('.ts')) {
|
|
80
|
-
return 'typescript';
|
|
96
|
+
return isLegacy ? 'commonjs-typescript' : 'typescript';
|
|
81
97
|
} else {
|
|
82
|
-
return
|
|
98
|
+
return null;
|
|
83
99
|
}
|
|
84
100
|
}
|
|
85
|
-
function
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
101
|
+
function toRealDirname(filePath) {
|
|
102
|
+
let normalized = _nodePath().default.resolve(filePath);
|
|
103
|
+
// Try resolving the filename itself first
|
|
104
|
+
try {
|
|
105
|
+
normalized = _nodeFs().default.realpathSync(normalized);
|
|
106
|
+
return _nodePath().default.dirname(normalized);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
normalized = _nodePath().default.dirname(normalized);
|
|
109
|
+
// If we're getting another error than an ENOENT, return the dirname unchanged
|
|
110
|
+
if (error?.code !== 'ENOENT') {
|
|
111
|
+
return normalized;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Alternatively, if it's a fake path, resolve the directory directly instead
|
|
115
|
+
try {
|
|
116
|
+
return _nodeFs().default.realpathSync(normalized);
|
|
117
|
+
} catch {
|
|
118
|
+
return normalized;
|
|
93
119
|
}
|
|
94
120
|
}
|
|
95
121
|
function compileModule(code, filename, opts) {
|
|
96
|
-
const format = toFormat(filename);
|
|
122
|
+
const format = toFormat(filename, false);
|
|
97
123
|
const prependPaths = opts.paths ?? [];
|
|
98
|
-
|
|
124
|
+
// See: https://github.com/nodejs/node/blob/ff080948666f28fbd767548d26bea034d30bc277/lib/internal/modules/cjs/loader.js#L767
|
|
125
|
+
// If we get a symlinked path instead of the realpath, we assume the realpath is needed for Node module resolution
|
|
126
|
+
const basePath = toRealDirname(filename);
|
|
127
|
+
const nodeModulePaths = nodeModule()._nodeModulePaths(basePath);
|
|
99
128
|
const paths = [...prependPaths, ...nodeModulePaths];
|
|
100
129
|
try {
|
|
101
130
|
const mod = Object.assign(new (nodeModule().Module)(filename, parent), {
|
|
102
131
|
filename,
|
|
103
132
|
paths
|
|
104
133
|
});
|
|
105
|
-
mod._compile(code, filename, format);
|
|
134
|
+
mod._compile(code, filename, format != null ? format : undefined);
|
|
135
|
+
mod.loaded = true;
|
|
106
136
|
require.cache[filename] = mod;
|
|
107
137
|
parent?.children?.splice(parent.children.indexOf(mod), 1);
|
|
108
|
-
return mod
|
|
138
|
+
return mod;
|
|
109
139
|
} catch (error) {
|
|
110
140
|
delete require.cache[filename];
|
|
111
141
|
throw error;
|
|
112
142
|
}
|
|
113
143
|
}
|
|
114
144
|
const hasStripTypeScriptTypes = typeof nodeModule().stripTypeScriptTypes === 'function';
|
|
115
|
-
function evalModule(code, filename, opts = {}) {
|
|
145
|
+
function evalModule(code, filename, opts = {}, format = toFormat(filename, true)) {
|
|
116
146
|
let inputCode = code;
|
|
117
147
|
let inputFilename = filename;
|
|
118
148
|
let diagnostic;
|
|
119
|
-
if (
|
|
120
|
-
const ext = _nodePath().default.extname(filename);
|
|
149
|
+
if (format === 'typescript' || format === 'module-typescript' || format === 'commonjs-typescript') {
|
|
121
150
|
const ts = loadTypescript();
|
|
122
151
|
if (ts) {
|
|
123
152
|
let module;
|
|
124
|
-
if (
|
|
153
|
+
if (format === 'commonjs-typescript') {
|
|
125
154
|
module = ts.ModuleKind.CommonJS;
|
|
126
|
-
} else if (
|
|
155
|
+
} else if (format === 'module-typescript') {
|
|
127
156
|
module = ts.ModuleKind.ESNext;
|
|
128
157
|
} else {
|
|
129
158
|
// NOTE(@kitten): We can "preserve" the output, meaning, it can either be ESM or CJS
|
|
@@ -159,22 +188,29 @@ function evalModule(code, filename, opts = {}) {
|
|
|
159
188
|
});
|
|
160
189
|
}
|
|
161
190
|
if (inputCode !== code) {
|
|
191
|
+
const ext = _nodePath().default.extname(filename);
|
|
162
192
|
const inputExt = tsExtensionMapping[ext] ?? ext;
|
|
163
193
|
if (inputExt !== ext) {
|
|
164
194
|
inputFilename = _nodePath().default.join(_nodePath().default.dirname(filename), _nodePath().default.basename(filename, ext) + inputExt);
|
|
165
195
|
}
|
|
166
196
|
}
|
|
197
|
+
} else if (format === 'commonjs') {
|
|
198
|
+
inputCode = (0, _transform().toCommonJS)(filename, code);
|
|
167
199
|
}
|
|
168
200
|
try {
|
|
169
201
|
const mod = compileModule(inputCode, inputFilename, opts);
|
|
170
202
|
if (inputFilename !== filename) {
|
|
171
203
|
require.cache[filename] = mod;
|
|
172
204
|
}
|
|
173
|
-
return mod;
|
|
205
|
+
return mod.exports;
|
|
174
206
|
} catch (error) {
|
|
175
207
|
// If we have a diagnostic from TypeScript, we issue its error with a codeframe first,
|
|
176
208
|
// since it's likely more useful than the eval error
|
|
177
|
-
|
|
209
|
+
const diagnosticError = (0, _codeframe().formatDiagnostic)(diagnostic);
|
|
210
|
+
if (diagnosticError) {
|
|
211
|
+
throw diagnosticError;
|
|
212
|
+
}
|
|
213
|
+
throw (0, _codeframe().annotateError)(code, filename, error) ?? error;
|
|
178
214
|
}
|
|
179
215
|
}
|
|
180
216
|
async function requireOrImport(filename) {
|
|
@@ -200,19 +236,30 @@ async function loadModule(filename) {
|
|
|
200
236
|
* NOTE: Requiring ESM has been added in all LTS versions (Node 20.19+, 22.12+, 24).
|
|
201
237
|
* This already forms the minimum required Node version as of Expo SDK 54 */
|
|
202
238
|
function loadModuleSync(filename) {
|
|
239
|
+
const format = toFormat(filename, true);
|
|
240
|
+
const isTypeScript = format === 'module-typescript' || format === 'commonjs-typescript' || format === 'typescript';
|
|
203
241
|
try {
|
|
204
|
-
if (!
|
|
242
|
+
if (format !== 'module' && !isTypeScript) {
|
|
205
243
|
return require(filename);
|
|
206
244
|
}
|
|
207
245
|
} catch (error) {
|
|
208
246
|
if (error.code === 'MODULE_NOT_FOUND') {
|
|
209
247
|
throw error;
|
|
248
|
+
} else if (format == null) {
|
|
249
|
+
const code = maybeReadFileSync(filename);
|
|
250
|
+
throw (0, _codeframe().annotateError)(code, filename, error) || error;
|
|
210
251
|
}
|
|
211
252
|
// We fallback to always evaluating the entrypoint module
|
|
212
253
|
// This is out of safety, since we're not trusting the requiring ESM feature
|
|
213
254
|
// and evaluating the module manually bypasses the error when it's flagged off
|
|
214
255
|
}
|
|
256
|
+
|
|
257
|
+
// Load from cache manually, if `loaded` is set and exports are defined, to avoid
|
|
258
|
+
// double transform or double evaluation
|
|
259
|
+
if (require.cache[filename]?.exports && require.cache[filename].loaded) {
|
|
260
|
+
return require.cache[filename].exports;
|
|
261
|
+
}
|
|
215
262
|
const code = _nodeFs().default.readFileSync(filename, 'utf8');
|
|
216
|
-
return evalModule(code, filename);
|
|
263
|
+
return evalModule(code, filename, {}, format);
|
|
217
264
|
}
|
|
218
265
|
//# sourceMappingURL=load.js.map
|
package/build/load.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load.js","names":["_nodeFs","data","_interopRequireDefault","require","nodeModule","_interopRequireWildcard","_nodePath","_nodeUrl","_codeframe","e","__esModule","default","_getRequireWildcardCache","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","_ts","loadTypescript","undefined","error","code","parent","module","tsExtensionMapping","toFormat","filename","endsWith","isTypescriptFilename","compileModule","opts","format","prependPaths","paths","nodeModulePaths","_nodeModulePaths","path","dirname","mod","assign","Module","_compile","cache","children","splice","indexOf","exports","hasStripTypeScriptTypes","stripTypeScriptTypes","evalModule","inputCode","inputFilename","diagnostic","ext","extname","ts","ModuleKind","CommonJS","ESNext","Preserve","output","transpileModule","fileName","reportDiagnostics","compilerOptions","moduleResolution","ModuleResolutionKind","Bundler","verbatimModuleSyntax","target","ScriptTarget","newLine","NewLineKind","LineFeed","inlineSourceMap","esModuleInterop","outputText","diagnostics","length","mode","sourceMap","inputExt","join","basename","formatDiagnostic","annotateError","requireOrImport","Promise","resolve","isAbsolute","url","pathToFileURL","toString","then","s","loadModule","loadModuleSync","fs","readFileSync"],"sources":["../src/load.ts"],"sourcesContent":["import fs from 'node:fs';\nimport * as nodeModule from 'node:module';\nimport path from 'node:path';\nimport url from 'node:url';\nimport type * as ts from 'typescript';\n\nimport { annotateError, formatDiagnostic } from './codeframe';\n\ndeclare module 'node:module' {\n export function _nodeModulePaths(base: string): readonly string[];\n}\n\ndeclare global {\n namespace NodeJS {\n export interface Module {\n _compile(\n code: string,\n filename: string,\n format?: 'module' | 'commonjs' | 'commonjs-typescript' | 'module-typescript' | 'typescript'\n ): unknown;\n }\n }\n}\n\nlet _ts: typeof import('typescript') | null | undefined;\nfunction loadTypescript() {\n if (_ts === undefined) {\n try {\n _ts = require('typescript');\n } catch (error: any) {\n if (error.code !== 'MODULE_NOT_FOUND') {\n throw error;\n } else {\n _ts = null;\n }\n }\n }\n return _ts;\n}\n\nconst parent = module;\n\nconst tsExtensionMapping: Record<string, string | undefined> = {\n '.ts': '.js',\n '.cts': '.cjs',\n '.mts': '.mjs',\n};\n\nfunction toFormat(filename: string) {\n if (filename.endsWith('.cjs')) {\n return 'commonjs';\n } else if (filename.endsWith('.mjs')) {\n return 'module';\n } else if (filename.endsWith('.js')) {\n return undefined;\n } else if (filename.endsWith('.mts')) {\n return 'module-typescript';\n } else if (filename.endsWith('.cts')) {\n return 'commonjs-typescript';\n } else if (filename.endsWith('.ts')) {\n return 'typescript';\n } else {\n return undefined;\n }\n}\n\nfunction isTypescriptFilename(filename: string) {\n switch (toFormat(filename)) {\n case 'module-typescript':\n case 'commonjs-typescript':\n case 'typescript':\n return true;\n default:\n return false;\n }\n}\n\nexport interface ModuleOptions {\n paths?: string[];\n}\n\nfunction compileModule<T = any>(code: string, filename: string, opts: ModuleOptions): T {\n const format = toFormat(filename);\n const prependPaths = opts.paths ?? [];\n const nodeModulePaths = nodeModule._nodeModulePaths(path.dirname(filename));\n const paths = [...prependPaths, ...nodeModulePaths];\n try {\n const mod = Object.assign(new nodeModule.Module(filename, parent), { filename, paths });\n mod._compile(code, filename, format);\n require.cache[filename] = mod;\n parent?.children?.splice(parent.children.indexOf(mod), 1);\n return mod.exports;\n } catch (error: any) {\n delete require.cache[filename];\n throw error;\n }\n}\n\nconst hasStripTypeScriptTypes = typeof nodeModule.stripTypeScriptTypes === 'function';\n\nfunction evalModule(code: string, filename: string, opts: ModuleOptions = {}) {\n let inputCode = code;\n let inputFilename = filename;\n let diagnostic: ts.Diagnostic | undefined;\n if (filename.endsWith('.ts') || filename.endsWith('.cts') || filename.endsWith('.mts')) {\n const ext = path.extname(filename);\n const ts = loadTypescript();\n\n if (ts) {\n let module: ts.ModuleKind;\n if (ext === '.cts') {\n module = ts.ModuleKind.CommonJS;\n } else if (ext === '.mts') {\n module = ts.ModuleKind.ESNext;\n } else {\n // NOTE(@kitten): We can \"preserve\" the output, meaning, it can either be ESM or CJS\n // and stop TypeScript from either transpiling it to CommonJS or adding an `export {}`\n // if no exports are used. This allows the user to choose if this file is CJS or ESM\n // (but not to mix both)\n module = ts.ModuleKind.Preserve;\n }\n const output = ts.transpileModule(code, {\n fileName: filename,\n reportDiagnostics: true,\n compilerOptions: {\n module,\n moduleResolution: ts.ModuleResolutionKind.Bundler,\n // `verbatimModuleSyntax` needs to be off, to erase as many imports as possible\n verbatimModuleSyntax: false,\n target: ts.ScriptTarget.ESNext,\n newLine: ts.NewLineKind.LineFeed,\n inlineSourceMap: true,\n esModuleInterop: true,\n },\n });\n inputCode = output?.outputText || inputCode;\n if (output?.diagnostics?.length) {\n diagnostic = output.diagnostics[0];\n }\n }\n\n if (hasStripTypeScriptTypes && inputCode === code) {\n // This may throw its own error, but this contains a code-frame already\n inputCode = nodeModule.stripTypeScriptTypes(code, {\n mode: 'transform',\n sourceMap: true,\n });\n }\n\n if (inputCode !== code) {\n const inputExt = tsExtensionMapping[ext] ?? ext;\n if (inputExt !== ext) {\n inputFilename = path.join(path.dirname(filename), path.basename(filename, ext) + inputExt);\n }\n }\n }\n\n try {\n const mod = compileModule(inputCode, inputFilename, opts);\n if (inputFilename !== filename) {\n require.cache[filename] = mod;\n }\n return mod;\n } catch (error: any) {\n // If we have a diagnostic from TypeScript, we issue its error with a codeframe first,\n // since it's likely more useful than the eval error\n throw formatDiagnostic(diagnostic) ?? annotateError(code, filename, error) ?? error;\n }\n}\n\nasync function requireOrImport(filename: string) {\n try {\n return require(filename);\n } catch {\n return await import(\n path.isAbsolute(filename) ? url.pathToFileURL(filename).toString() : filename\n );\n }\n}\n\nasync function loadModule(filename: string) {\n try {\n return await requireOrImport(filename);\n } catch (error: any) {\n if (error.code === 'ERR_UNKNOWN_FILE_EXTENSION' || error.code === 'MODULE_NOT_FOUND') {\n return loadModuleSync(filename);\n } else {\n throw error;\n }\n }\n}\n\n/** Require module or evaluate with TypeScript\n * NOTE: Requiring ESM has been added in all LTS versions (Node 20.19+, 22.12+, 24).\n * This already forms the minimum required Node version as of Expo SDK 54 */\nfunction loadModuleSync(filename: string) {\n try {\n if (!isTypescriptFilename(filename)) {\n return require(filename);\n }\n } catch (error: any) {\n if (error.code === 'MODULE_NOT_FOUND') {\n throw error;\n }\n // We fallback to always evaluating the entrypoint module\n // This is out of safety, since we're not trusting the requiring ESM feature\n // and evaluating the module manually bypasses the error when it's flagged off\n }\n const code = fs.readFileSync(filename, 'utf8');\n return evalModule(code, filename);\n}\n\n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F,QAAQ,CAAC,EAAE;MACnC,OAAOnC,OAAO,CAACmC,QAAQ,CAAC;IAC1B;EACF,CAAC,CAAC,OAAON,KAAU,EAAE;IACnB,IAAIA,KAAK,CAACC,IAAI,KAAK,kBAAkB,EAAE;MACrC,MAAMD,KAAK;IACb;IACA;IACA;IACA;EACF;EACA,MAAMC,IAAI,GAAG4E,iBAAE,CAACC,YAAY,CAACxE,QAAQ,EAAE,MAAM,CAAC;EAC9C,OAAOuB,UAAU,CAAC5B,IAAI,EAAEK,QAAQ,CAAC;AACnC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"load.js","names":["_nodeFs","data","_interopRequireDefault","require","nodeModule","_interopRequireWildcard","_nodePath","_nodeUrl","_codeframe","_transform","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_ts","loadTypescript","undefined","error","code","parent","module","tsExtensionMapping","maybeReadFileSync","filename","fs","readFileSync","toFormat","isLegacy","endsWith","toRealDirname","filePath","normalized","path","resolve","realpathSync","dirname","compileModule","opts","format","prependPaths","paths","basePath","nodeModulePaths","_nodeModulePaths","mod","assign","Module","_compile","loaded","cache","children","splice","indexOf","hasStripTypeScriptTypes","stripTypeScriptTypes","evalModule","inputCode","inputFilename","diagnostic","ts","ModuleKind","CommonJS","ESNext","Preserve","output","transpileModule","fileName","reportDiagnostics","compilerOptions","moduleResolution","ModuleResolutionKind","Bundler","verbatimModuleSyntax","target","ScriptTarget","newLine","NewLineKind","LineFeed","inlineSourceMap","esModuleInterop","outputText","diagnostics","length","mode","sourceMap","ext","extname","inputExt","join","basename","toCommonJS","exports","diagnosticError","formatDiagnostic","annotateError","requireOrImport","Promise","isAbsolute","url","pathToFileURL","toString","then","s","loadModule","loadModuleSync","isTypeScript"],"sources":["../src/load.ts"],"sourcesContent":["import fs from 'node:fs';\nimport * as nodeModule from 'node:module';\nimport path from 'node:path';\nimport url from 'node:url';\nimport type * as ts from 'typescript';\n\nimport { annotateError, formatDiagnostic } from './codeframe';\nimport { toCommonJS } from './transform';\n\ndeclare module 'node:module' {\n export function _nodeModulePaths(base: string): readonly string[];\n}\n\ndeclare global {\n namespace NodeJS {\n export interface Module {\n _compile(\n code: string,\n filename: string,\n format?: 'module' | 'commonjs' | 'commonjs-typescript' | 'module-typescript' | 'typescript'\n ): unknown;\n }\n }\n}\n\nlet _ts: typeof import('typescript') | null | undefined;\nfunction loadTypescript() {\n if (_ts === undefined) {\n try {\n _ts = require('typescript');\n } catch (error: any) {\n if (error.code !== 'MODULE_NOT_FOUND') {\n throw error;\n } else {\n _ts = null;\n }\n }\n }\n return _ts;\n}\n\nconst parent = module;\n\nconst tsExtensionMapping: Record<string, string | undefined> = {\n '.ts': '.js',\n '.cts': '.cjs',\n '.mts': '.mjs',\n};\n\nfunction maybeReadFileSync(filename: string) {\n try {\n return fs.readFileSync(filename, 'utf8');\n } catch (error: any) {\n if (error.code === 'ENOENT') {\n return null;\n }\n throw error;\n }\n}\n\ntype Format = 'commonjs' | 'module' | 'module-typescript' | 'commonjs-typescript' | 'typescript';\n\nfunction toFormat(filename: string, isLegacy: true): Format;\nfunction toFormat(filename: string, isLegacy: false): Format | null;\nfunction toFormat(filename: string, isLegacy: boolean): Format | null {\n if (filename.endsWith('.cjs')) {\n return 'commonjs';\n } else if (filename.endsWith('.mjs')) {\n return 'module';\n } else if (filename.endsWith('.js')) {\n return isLegacy ? 'commonjs' : null;\n } else if (filename.endsWith('.mts')) {\n return 'module-typescript';\n } else if (filename.endsWith('.cts')) {\n return 'commonjs-typescript';\n } else if (filename.endsWith('.ts')) {\n return isLegacy ? 'commonjs-typescript' : 'typescript';\n } else {\n return null;\n }\n}\n\nexport interface ModuleOptions {\n paths?: string[];\n}\n\nfunction toRealDirname(filePath: string): string {\n let normalized = path.resolve(filePath);\n // Try resolving the filename itself first\n try {\n normalized = fs.realpathSync(normalized);\n return path.dirname(normalized);\n } catch (error: any) {\n normalized = path.dirname(normalized);\n // If we're getting another error than an ENOENT, return the dirname unchanged\n if (error?.code !== 'ENOENT') {\n return normalized;\n }\n }\n // Alternatively, if it's a fake path, resolve the directory directly instead\n try {\n return fs.realpathSync(normalized);\n } catch {\n return normalized;\n }\n}\n\nfunction compileModule(code: string, filename: string, opts: ModuleOptions) {\n const format = toFormat(filename, false);\n const prependPaths = opts.paths ?? [];\n // See: https://github.com/nodejs/node/blob/ff080948666f28fbd767548d26bea034d30bc277/lib/internal/modules/cjs/loader.js#L767\n // If we get a symlinked path instead of the realpath, we assume the realpath is needed for Node module resolution\n const basePath = toRealDirname(filename);\n const nodeModulePaths = nodeModule._nodeModulePaths(basePath);\n const paths = [...prependPaths, ...nodeModulePaths];\n try {\n const mod = Object.assign(new nodeModule.Module(filename, parent), { filename, paths });\n mod._compile(code, filename, format != null ? format : undefined);\n mod.loaded = true;\n require.cache[filename] = mod;\n parent?.children?.splice(parent.children.indexOf(mod), 1);\n return mod;\n } catch (error: any) {\n delete require.cache[filename];\n throw error;\n }\n}\n\nconst hasStripTypeScriptTypes = typeof nodeModule.stripTypeScriptTypes === 'function';\n\nfunction evalModule(\n code: string,\n filename: string,\n opts: ModuleOptions = {},\n format: Format = toFormat(filename, true)\n) {\n let inputCode = code;\n let inputFilename = filename;\n let diagnostic: ts.Diagnostic | undefined;\n if (\n format === 'typescript' ||\n format === 'module-typescript' ||\n format === 'commonjs-typescript'\n ) {\n const ts = loadTypescript();\n\n if (ts) {\n let module: ts.ModuleKind;\n if (format === 'commonjs-typescript') {\n module = ts.ModuleKind.CommonJS;\n } else if (format === 'module-typescript') {\n module = ts.ModuleKind.ESNext;\n } else {\n // NOTE(@kitten): We can \"preserve\" the output, meaning, it can either be ESM or CJS\n // and stop TypeScript from either transpiling it to CommonJS or adding an `export {}`\n // if no exports are used. This allows the user to choose if this file is CJS or ESM\n // (but not to mix both)\n module = ts.ModuleKind.Preserve;\n }\n const output = ts.transpileModule(code, {\n fileName: filename,\n reportDiagnostics: true,\n compilerOptions: {\n module,\n moduleResolution: ts.ModuleResolutionKind.Bundler,\n // `verbatimModuleSyntax` needs to be off, to erase as many imports as possible\n verbatimModuleSyntax: false,\n target: ts.ScriptTarget.ESNext,\n newLine: ts.NewLineKind.LineFeed,\n inlineSourceMap: true,\n esModuleInterop: true,\n },\n });\n inputCode = output?.outputText || inputCode;\n if (output?.diagnostics?.length) {\n diagnostic = output.diagnostics[0];\n }\n }\n\n if (hasStripTypeScriptTypes && inputCode === code) {\n // This may throw its own error, but this contains a code-frame already\n inputCode = nodeModule.stripTypeScriptTypes(code, {\n mode: 'transform',\n sourceMap: true,\n });\n }\n\n if (inputCode !== code) {\n const ext = path.extname(filename);\n const inputExt = tsExtensionMapping[ext] ?? ext;\n if (inputExt !== ext) {\n inputFilename = path.join(path.dirname(filename), path.basename(filename, ext) + inputExt);\n }\n }\n } else if (format === 'commonjs') {\n inputCode = toCommonJS(filename, code);\n }\n\n try {\n const mod = compileModule(inputCode, inputFilename, opts);\n if (inputFilename !== filename) {\n require.cache[filename] = mod;\n }\n return mod.exports;\n } catch (error: any) {\n // If we have a diagnostic from TypeScript, we issue its error with a codeframe first,\n // since it's likely more useful than the eval error\n const diagnosticError = formatDiagnostic(diagnostic);\n if (diagnosticError) {\n throw diagnosticError;\n }\n throw annotateError(code, filename, error) ?? error;\n }\n}\n\nasync function requireOrImport(filename: string) {\n try {\n return require(filename);\n } catch {\n return await import(\n path.isAbsolute(filename) ? url.pathToFileURL(filename).toString() : filename\n );\n }\n}\n\nasync function loadModule(filename: string) {\n try {\n return await requireOrImport(filename);\n } catch (error: any) {\n if (error.code === 'ERR_UNKNOWN_FILE_EXTENSION' || error.code === 'MODULE_NOT_FOUND') {\n return loadModuleSync(filename);\n } else {\n throw error;\n }\n }\n}\n\n/** Require module or evaluate with TypeScript\n * NOTE: Requiring ESM has been added in all LTS versions (Node 20.19+, 22.12+, 24).\n * This already forms the minimum required Node version as of Expo SDK 54 */\nfunction loadModuleSync(filename: string) {\n const format = toFormat(filename, true);\n const isTypeScript =\n format === 'module-typescript' || format === 'commonjs-typescript' || format === 'typescript';\n try {\n if (format !== 'module' && !isTypeScript) {\n return require(filename);\n }\n } catch (error: any) {\n if (error.code === 'MODULE_NOT_FOUND') {\n throw error;\n } else if (format == null) {\n const code = maybeReadFileSync(filename);\n throw annotateError(code, filename, error) || error;\n }\n // We fallback to always evaluating the entrypoint module\n // This is out of safety, since we're not trusting the requiring ESM feature\n // and evaluating the module manually bypasses the error when it's flagged off\n }\n\n // Load from cache manually, if `loaded` is set and exports are defined, to avoid\n // double transform or double evaluation\n if (require.cache[filename]?.exports && require.cache[filename].loaded) {\n return require.cache[filename].exports;\n }\n\n const code = fs.readFileSync(filename, 'utf8');\n return evalModule(code, filename, {}, format);\n}\n\nexport { evalModule, loadModule, loadModuleSync };\n"],"mappings":";;;;;;;;AAAA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,WAAA;EAAA,MAAAH,IAAA,GAAAI,uBAAA,CAAAF,OAAA;EAAAC,UAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,UAAA;EAAA,MAAAL,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAG,SAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,SAAA;EAAA,MAAAN,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAI,QAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAO,WAAA;EAAA,MAAAP,IAAA,GAAAE,OAAA;EAAAK,UAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAQ,WAAA;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
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare module 'node:module' {
|
|
2
|
+
function _nodeModulePaths(base: string): readonly string[];
|
|
3
|
+
function _resolveFilename(mod: string, parent?: Partial<Module>): string;
|
|
4
|
+
const _extensions: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
export interface ResolveFromParams {
|
|
7
|
+
followSymlinks?: boolean;
|
|
8
|
+
extensions?: readonly string[];
|
|
9
|
+
}
|
|
10
|
+
export declare function resolveFrom(fromDirectory: string, moduleId: string, params?: ResolveFromParams): string | null;
|
package/build/resolve.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.resolveFrom = resolveFrom;
|
|
7
|
+
function _nodeFs() {
|
|
8
|
+
const data = _interopRequireDefault(require("node:fs"));
|
|
9
|
+
_nodeFs = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _nodeModule() {
|
|
15
|
+
const data = _interopRequireDefault(require("node:module"));
|
|
16
|
+
_nodeModule = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _nodePath() {
|
|
22
|
+
const data = _interopRequireDefault(require("node:path"));
|
|
23
|
+
_nodePath = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
29
|
+
function resolveFrom(fromDirectory, moduleId, params) {
|
|
30
|
+
const exts = params?.extensions ?? Object.keys(_nodeModule().default._extensions);
|
|
31
|
+
const resolved = _nodePath().default.resolve(fromDirectory, moduleId);
|
|
32
|
+
// (1) check direct path / exact match
|
|
33
|
+
if (_nodeFs().default.existsSync(resolved)) {
|
|
34
|
+
return resolved;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// (2) check against direct path matches with extensions
|
|
38
|
+
for (let ext of exts) {
|
|
39
|
+
ext = ext[0] !== '.' ? `.${ext}` : ext;
|
|
40
|
+
const withExt = resolved + ext;
|
|
41
|
+
if (_nodeFs().default.existsSync(withExt)) {
|
|
42
|
+
return withExt;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// (3) if we're not following symlinks, we try to resolve against `node_modules` folders unresolved
|
|
47
|
+
if (!params?.followSymlinks) {
|
|
48
|
+
const resolvedDir = _nodePath().default.resolve(fromDirectory);
|
|
49
|
+
const moduleDirs = _nodeModule().default._nodeModulePaths(resolvedDir);
|
|
50
|
+
for (const modulesDir of moduleDirs) {
|
|
51
|
+
const candidate = _nodePath().default.join(modulesDir, moduleId);
|
|
52
|
+
// (3.1) direct match
|
|
53
|
+
if (_nodeFs().default.existsSync(candidate)) {
|
|
54
|
+
return candidate;
|
|
55
|
+
}
|
|
56
|
+
// (3.2) check against match with extensions
|
|
57
|
+
for (let ext of exts) {
|
|
58
|
+
ext = ext[0] !== '.' ? `.${ext}` : ext;
|
|
59
|
+
const candidateWithExt = candidate + ext;
|
|
60
|
+
if (_nodeFs().default.existsSync(candidateWithExt)) {
|
|
61
|
+
return candidateWithExt;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// (4): Fallback to native Node resolution
|
|
68
|
+
return nativeResolveFrom(fromDirectory, moduleId);
|
|
69
|
+
}
|
|
70
|
+
function nativeResolveFrom(fromDirectory, moduleId) {
|
|
71
|
+
try {
|
|
72
|
+
const resolvedDir = maybeResolve(fromDirectory);
|
|
73
|
+
const fromFile = _nodePath().default.join(resolvedDir, 'index.js');
|
|
74
|
+
return _nodeModule().default._resolveFilename(moduleId, {
|
|
75
|
+
id: fromFile,
|
|
76
|
+
filename: fromFile,
|
|
77
|
+
paths: [..._nodeModule().default._nodeModulePaths(resolvedDir)]
|
|
78
|
+
});
|
|
79
|
+
} catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function maybeResolve(target) {
|
|
84
|
+
target = _nodePath().default.resolve(process.cwd(), target);
|
|
85
|
+
try {
|
|
86
|
+
return _nodeFs().default.realpathSync(target);
|
|
87
|
+
} catch {
|
|
88
|
+
return target;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","names":["_nodeFs","data","_interopRequireDefault","require","_nodeModule","_nodePath","e","__esModule","default","resolveFrom","fromDirectory","moduleId","params","exts","extensions","Object","keys","Module","_extensions","resolved","path","resolve","fs","existsSync","ext","withExt","followSymlinks","resolvedDir","moduleDirs","_nodeModulePaths","modulesDir","candidate","join","candidateWithExt","nativeResolveFrom","maybeResolve","fromFile","_resolveFilename","id","filename","paths","target","process","cwd","realpathSync"],"sources":["../src/resolve.ts"],"sourcesContent":["import fs from 'node:fs';\nimport Module from 'node:module';\nimport path from 'node:path';\n\ndeclare module 'node:module' {\n export function _nodeModulePaths(base: string): readonly string[];\n export function _resolveFilename(mod: string, parent?: Partial<Module>): string;\n export const _extensions: Record<string, unknown>;\n}\n\nexport interface ResolveFromParams {\n followSymlinks?: boolean;\n extensions?: readonly string[];\n}\n\nexport function resolveFrom(\n fromDirectory: string,\n moduleId: string,\n params?: ResolveFromParams\n): string | null {\n const exts = params?.extensions ?? Object.keys(Module._extensions);\n const resolved = path.resolve(fromDirectory, moduleId);\n // (1) check direct path / exact match\n if (fs.existsSync(resolved)) {\n return resolved;\n }\n\n // (2) check against direct path matches with extensions\n for (let ext of exts) {\n ext = ext[0] !== '.' ? `.${ext}` : ext;\n const withExt = resolved + ext;\n if (fs.existsSync(withExt)) {\n return withExt;\n }\n }\n\n // (3) if we're not following symlinks, we try to resolve against `node_modules` folders unresolved\n if (!params?.followSymlinks) {\n const resolvedDir = path.resolve(fromDirectory);\n const moduleDirs = Module._nodeModulePaths(resolvedDir);\n for (const modulesDir of moduleDirs) {\n const candidate = path.join(modulesDir, moduleId);\n // (3.1) direct match\n if (fs.existsSync(candidate)) {\n return candidate;\n }\n // (3.2) check against match with extensions\n for (let ext of exts) {\n ext = ext[0] !== '.' ? `.${ext}` : ext;\n const candidateWithExt = candidate + ext;\n if (fs.existsSync(candidateWithExt)) {\n return candidateWithExt;\n }\n }\n }\n }\n\n // (4): Fallback to native Node resolution\n return nativeResolveFrom(fromDirectory, moduleId);\n}\n\nfunction nativeResolveFrom(fromDirectory: string, moduleId: string): string | null {\n try {\n const resolvedDir = maybeResolve(fromDirectory);\n const fromFile = path.join(resolvedDir, 'index.js');\n return Module._resolveFilename(moduleId, {\n id: fromFile,\n filename: fromFile,\n paths: [...Module._nodeModulePaths(resolvedDir)],\n });\n } catch {\n return null;\n }\n}\n\nfunction maybeResolve(target: string): string {\n target = path.resolve(process.cwd(), target);\n try {\n return fs.realpathSync(target);\n } catch {\n return target;\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,YAAA;EAAA,MAAAH,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAC,WAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,UAAA;EAAA,MAAAJ,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAE,SAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA6B,SAAAC,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAA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AACC,UAAU,CAACU,gBAAgB,CAAC,EAAE;UACnC,OAAOA,gBAAgB;QACzB;MACF;IACF;EACF;;EAEA;EACA,OAAOC,iBAAiB,CAACxB,aAAa,EAAEC,QAAQ,CAAC;AACnD;AAEA,SAASuB,iBAAiBA,CAACxB,aAAqB,EAAEC,QAAgB,EAAiB;EACjF,IAAI;IACF,MAAMgB,WAAW,GAAGQ,YAAY,CAACzB,aAAa,CAAC;IAC/C,MAAM0B,QAAQ,GAAGhB,mBAAI,CAACY,IAAI,CAACL,WAAW,EAAE,UAAU,CAAC;IACnD,OAAOV,qBAAM,CAACoB,gBAAgB,CAAC1B,QAAQ,EAAE;MACvC2B,EAAE,EAAEF,QAAQ;MACZG,QAAQ,EAAEH,QAAQ;MAClBI,KAAK,EAAE,CAAC,GAAGvB,qBAAM,CAACY,gBAAgB,CAACF,WAAW,CAAC;IACjD,CAAC,CAAC;EACJ,CAAC,CAAC,MAAM;IACN,OAAO,IAAI;EACb;AACF;AAEA,SAASQ,YAAYA,CAACM,MAAc,EAAU;EAC5CA,MAAM,GAAGrB,mBAAI,CAACC,OAAO,CAACqB,OAAO,CAACC,GAAG,CAAC,CAAC,EAAEF,MAAM,CAAC;EAC5C,IAAI;IACF,OAAOnB,iBAAE,CAACsB,YAAY,CAACH,MAAM,CAAC;EAChC,CAAC,CAAC,MAAM;IACN,OAAOA,MAAM;EACf;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.resolveGlobal = void 0;
|
|
7
|
+
function _nodeChild_process() {
|
|
8
|
+
const data = require("node:child_process");
|
|
9
|
+
_nodeChild_process = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _nodeFs() {
|
|
15
|
+
const data = _interopRequireDefault(require("node:fs"));
|
|
16
|
+
_nodeFs = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _nodeModule() {
|
|
22
|
+
const data = _interopRequireDefault(require("node:module"));
|
|
23
|
+
_nodeModule = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
function _nodeOs() {
|
|
29
|
+
const data = _interopRequireDefault(require("node:os"));
|
|
30
|
+
_nodeOs = function () {
|
|
31
|
+
return data;
|
|
32
|
+
};
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
function _nodePath() {
|
|
36
|
+
const data = _interopRequireDefault(require("node:path"));
|
|
37
|
+
_nodePath = function () {
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
40
|
+
return data;
|
|
41
|
+
}
|
|
42
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
43
|
+
const memoize = fn => {
|
|
44
|
+
let result;
|
|
45
|
+
return (...args) => {
|
|
46
|
+
if (result === undefined) {
|
|
47
|
+
result = {
|
|
48
|
+
value: fn(...args)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return result.value;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const isWindows = process.platform === 'win32';
|
|
55
|
+
const getDelimitedPaths = delimited => delimited.split(_nodePath().default.delimiter).map(target => {
|
|
56
|
+
try {
|
|
57
|
+
const normalized = _nodePath().default.normalize(target.trim());
|
|
58
|
+
if (!normalized) {
|
|
59
|
+
return null;
|
|
60
|
+
} else if (!_nodePath().default.isAbsolute(normalized)) {
|
|
61
|
+
return _nodePath().default.resolve(process.cwd(), normalized);
|
|
62
|
+
} else {
|
|
63
|
+
return normalized;
|
|
64
|
+
}
|
|
65
|
+
} catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}).filter(target => !!target);
|
|
69
|
+
const execGetPaths = (cmd, args) => {
|
|
70
|
+
const result = (0, _nodeChild_process().spawnSync)(cmd, args, {
|
|
71
|
+
encoding: 'utf8'
|
|
72
|
+
});
|
|
73
|
+
if (!result.error && result.status === 0 && result.stdout) {
|
|
74
|
+
const paths = getDelimitedPaths(result.stdout.replace(/[\r\n]+/g, _nodePath().default.delimiter));
|
|
75
|
+
return paths.filter(target => _nodeFs().default.existsSync(target));
|
|
76
|
+
}
|
|
77
|
+
return [];
|
|
78
|
+
};
|
|
79
|
+
const getNativeNodePaths = () => {
|
|
80
|
+
if (Array.isArray(_nodeModule().default.globalPaths)) {
|
|
81
|
+
return _nodeModule().default.globalPaths;
|
|
82
|
+
} else {
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const getHomePath = memoize(() => {
|
|
87
|
+
try {
|
|
88
|
+
return _nodeOs().default.homedir();
|
|
89
|
+
} catch {
|
|
90
|
+
return isWindows ? process.env.UserProfile ?? process.env.USERPROFILE : process.env.HOME;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
const getNpmDefaultPaths = () => {
|
|
94
|
+
const prefix = [];
|
|
95
|
+
const localAppData = process.env.LocalAppData || process.env.LOCALAPPDATA;
|
|
96
|
+
if (isWindows && localAppData) {
|
|
97
|
+
prefix.push(_nodePath().default.resolve(localAppData, 'npm'));
|
|
98
|
+
} else if (!isWindows) {
|
|
99
|
+
prefix.push('/usr/local/lib/node_modules');
|
|
100
|
+
}
|
|
101
|
+
return prefix.filter(target => _nodeFs().default.existsSync(target));
|
|
102
|
+
};
|
|
103
|
+
const getNpmPrefixPaths = memoize(() => {
|
|
104
|
+
const npmPrefix = execGetPaths(isWindows ? 'npm.cmd' : 'npm', ['config', '-g', 'get', 'prefix']);
|
|
105
|
+
return npmPrefix.map(prefix => _nodePath().default.resolve(prefix, 'lib'));
|
|
106
|
+
});
|
|
107
|
+
const getYarnDefaultPaths = () => {
|
|
108
|
+
const prefix = [];
|
|
109
|
+
const homePath = getHomePath();
|
|
110
|
+
const localAppData = process.env.LocalAppData || process.env.LOCALAPPDATA;
|
|
111
|
+
const dataHomePath = process.env.XDG_DATA_HOME || homePath && _nodePath().default.join(homePath, '.local', 'share');
|
|
112
|
+
if (isWindows && localAppData) {
|
|
113
|
+
prefix.push(_nodePath().default.resolve(localAppData, 'Yarn', 'global'));
|
|
114
|
+
}
|
|
115
|
+
if (dataHomePath) {
|
|
116
|
+
prefix.push(_nodePath().default.resolve(dataHomePath, 'yarn', 'global'));
|
|
117
|
+
}
|
|
118
|
+
if (homePath) {
|
|
119
|
+
prefix.push(_nodePath().default.resolve(homePath, '.yarn', 'global'));
|
|
120
|
+
}
|
|
121
|
+
return prefix.filter(target => _nodeFs().default.existsSync(target));
|
|
122
|
+
};
|
|
123
|
+
const getYarnPrefixPaths = memoize(() => {
|
|
124
|
+
return execGetPaths(isWindows ? 'yarn.cmd' : 'yarn', ['global', 'dir']);
|
|
125
|
+
});
|
|
126
|
+
const getPnpmPrefixPaths = memoize(() => {
|
|
127
|
+
return execGetPaths(isWindows ? 'pnpm.cmd' : 'pnpm', ['root', '-g']);
|
|
128
|
+
});
|
|
129
|
+
const getBunPrefixPaths = memoize(() => {
|
|
130
|
+
const prefix = [];
|
|
131
|
+
const bunPath = execGetPaths(isWindows ? 'bun.cmd' : 'bun', ['pm', 'bin', '-g'])[0];
|
|
132
|
+
if (!bunPath) {
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
prefix.push(_nodePath().default.resolve(bunPath, 'global'));
|
|
136
|
+
const moduleEntry = _nodeFs().default.readdirSync(bunPath, {
|
|
137
|
+
withFileTypes: true
|
|
138
|
+
}).find(entry => {
|
|
139
|
+
return entry.isSymbolicLink() && entry.name !== 'global';
|
|
140
|
+
});
|
|
141
|
+
if (moduleEntry) {
|
|
142
|
+
try {
|
|
143
|
+
const moduleTarget = _nodeFs().default.realpathSync(_nodePath().default.resolve(bunPath, moduleEntry.name));
|
|
144
|
+
const splitIdx = moduleTarget.indexOf(_nodePath().default.sep + 'node_modules' + _nodePath().default.sep);
|
|
145
|
+
if (splitIdx > -1) {
|
|
146
|
+
const modulePath = moduleTarget.slice(0, splitIdx);
|
|
147
|
+
prefix.push(modulePath);
|
|
148
|
+
}
|
|
149
|
+
} catch {}
|
|
150
|
+
}
|
|
151
|
+
return prefix.filter(target => _nodeFs().default.existsSync(target));
|
|
152
|
+
});
|
|
153
|
+
const getPaths = () => [...getNpmDefaultPaths(), ...getNpmPrefixPaths(), ...getYarnDefaultPaths(), ...getYarnPrefixPaths(), ...getPnpmPrefixPaths(), ...getBunPrefixPaths(), ...getNativeNodePaths(), process.cwd()];
|
|
154
|
+
|
|
155
|
+
/** Resolve a globally installed module before a locally installed one */
|
|
156
|
+
const resolveGlobal = id => {
|
|
157
|
+
return require.resolve(id, {
|
|
158
|
+
paths: getPaths()
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
exports.resolveGlobal = resolveGlobal;
|
|
162
|
+
//# sourceMappingURL=resolveGlobal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveGlobal.js","names":["_nodeChild_process","data","require","_nodeFs","_interopRequireDefault","_nodeModule","_nodeOs","_nodePath","e","__esModule","default","memoize","fn","result","args","undefined","value","isWindows","process","platform","getDelimitedPaths","delimited","split","path","delimiter","map","target","normalized","normalize","trim","isAbsolute","resolve","cwd","filter","execGetPaths","cmd","spawnSync","encoding","error","status","stdout","paths","replace","fs","existsSync","getNativeNodePaths","Array","isArray","Module","globalPaths","getHomePath","os","homedir","env","UserProfile","USERPROFILE","HOME","getNpmDefaultPaths","prefix","localAppData","LocalAppData","LOCALAPPDATA","push","getNpmPrefixPaths","npmPrefix","getYarnDefaultPaths","homePath","dataHomePath","XDG_DATA_HOME","join","getYarnPrefixPaths","getPnpmPrefixPaths","getBunPrefixPaths","bunPath","moduleEntry","readdirSync","withFileTypes","find","entry","isSymbolicLink","name","moduleTarget","realpathSync","splitIdx","indexOf","sep","modulePath","slice","getPaths","resolveGlobal","id","exports"],"sources":["../src/resolveGlobal.ts"],"sourcesContent":["import { spawnSync } from 'node:child_process';\nimport fs from 'node:fs';\nimport Module from 'node:module';\nimport os from 'node:os';\nimport path from 'node:path';\n\ndeclare module 'node:module' {\n namespace Module {\n const globalPaths: readonly string[] | void;\n }\n}\n\nconst memoize = <Args extends any[], T>(fn: (...args: Args) => T): ((...args: Args) => T) => {\n let result: { value: T } | undefined;\n return (...args: Args): T => {\n if (result === undefined) {\n result = { value: fn(...args) };\n }\n return result.value;\n };\n};\n\nconst isWindows = process.platform === 'win32';\n\nconst getDelimitedPaths = (delimited: string): string[] =>\n delimited\n .split(path.delimiter)\n .map((target) => {\n try {\n const normalized = path.normalize(target.trim());\n if (!normalized) {\n return null;\n } else if (!path.isAbsolute(normalized)) {\n return path.resolve(process.cwd(), normalized);\n } else {\n return normalized;\n }\n } catch {\n return null;\n }\n })\n .filter((target): target is string => !!target);\n\nconst execGetPaths = (cmd: string, args: string[]): string[] => {\n const result = spawnSync(cmd, args, { encoding: 'utf8' });\n if (!result.error && result.status === 0 && result.stdout) {\n const paths = getDelimitedPaths(result.stdout.replace(/[\\r\\n]+/g, path.delimiter));\n return paths.filter((target) => fs.existsSync(target));\n }\n return [];\n};\n\nconst getNativeNodePaths = () => {\n if (Array.isArray(Module.globalPaths)) {\n return Module.globalPaths;\n } else {\n return [];\n }\n};\n\nconst getHomePath = memoize(() => {\n try {\n return os.homedir();\n } catch {\n return isWindows ? (process.env.UserProfile ?? process.env.USERPROFILE) : process.env.HOME;\n }\n});\n\nconst getNpmDefaultPaths = () => {\n const prefix = [];\n const localAppData = process.env.LocalAppData || process.env.LOCALAPPDATA;\n if (isWindows && localAppData) {\n prefix.push(path.resolve(localAppData, 'npm'));\n } else if (!isWindows) {\n prefix.push('/usr/local/lib/node_modules');\n }\n return prefix.filter((target) => fs.existsSync(target));\n};\n\nconst getNpmPrefixPaths = memoize(() => {\n const npmPrefix = execGetPaths(isWindows ? 'npm.cmd' : 'npm', ['config', '-g', 'get', 'prefix']);\n return npmPrefix.map((prefix) => path.resolve(prefix, 'lib'));\n});\n\nconst getYarnDefaultPaths = () => {\n const prefix = [];\n const homePath = getHomePath();\n const localAppData = process.env.LocalAppData || process.env.LOCALAPPDATA;\n const dataHomePath =\n process.env.XDG_DATA_HOME || (homePath && path.join(homePath, '.local', 'share'));\n if (isWindows && localAppData) {\n prefix.push(path.resolve(localAppData, 'Yarn', 'global'));\n }\n if (dataHomePath) {\n prefix.push(path.resolve(dataHomePath, 'yarn', 'global'));\n }\n if (homePath) {\n prefix.push(path.resolve(homePath, '.yarn', 'global'));\n }\n return prefix.filter((target) => fs.existsSync(target));\n};\n\nconst getYarnPrefixPaths = memoize(() => {\n return execGetPaths(isWindows ? 'yarn.cmd' : 'yarn', ['global', 'dir']);\n});\n\nconst getPnpmPrefixPaths = memoize(() => {\n return execGetPaths(isWindows ? 'pnpm.cmd' : 'pnpm', ['root', '-g']);\n});\n\nconst getBunPrefixPaths = memoize(() => {\n const prefix = [];\n const bunPath = execGetPaths(isWindows ? 'bun.cmd' : 'bun', ['pm', 'bin', '-g'])[0];\n if (!bunPath) {\n return [];\n }\n prefix.push(path.resolve(bunPath, 'global'));\n const moduleEntry = fs.readdirSync(bunPath, { withFileTypes: true }).find((entry) => {\n return entry.isSymbolicLink() && entry.name !== 'global';\n });\n if (moduleEntry) {\n try {\n const moduleTarget = fs.realpathSync(path.resolve(bunPath, moduleEntry.name));\n const splitIdx = moduleTarget.indexOf(path.sep + 'node_modules' + path.sep);\n if (splitIdx > -1) {\n const modulePath = moduleTarget.slice(0, splitIdx);\n prefix.push(modulePath);\n }\n } catch {}\n }\n return prefix.filter((target) => fs.existsSync(target));\n});\n\nconst getPaths = () => [\n ...getNpmDefaultPaths(),\n ...getNpmPrefixPaths(),\n ...getYarnDefaultPaths(),\n ...getYarnPrefixPaths(),\n ...getPnpmPrefixPaths(),\n ...getBunPrefixPaths(),\n ...getNativeNodePaths(),\n process.cwd(),\n];\n\n/** Resolve a globally installed module before a locally installed one */\nexport const resolveGlobal = (id: string): string => {\n return require.resolve(id, { paths: getPaths() });\n};\n"],"mappings":";;;;;;AAAA,SAAAA,mBAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,kBAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,QAAA;EAAA,MAAAF,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,YAAA;EAAA,MAAAJ,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAG,WAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,QAAA;EAAA,MAAAL,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAI,OAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,UAAA;EAAA,MAAAN,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAK,SAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA6B,SAAAG,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAQ7B,MAAMG,OAAO,GAA2BC,EAAwB,IAA6B;EAC3F,IAAIC,MAAgC;EACpC,OAAO,CAAC,GAAGC,IAAU,KAAQ;IAC3B,IAAID,MAAM,KAAKE,SAAS,EAAE;MACxBF,MAAM,GAAG;QAAEG,KAAK,EAAEJ,EAAE,CAAC,GAAGE,IAAI;MAAE,CAAC;IACjC;IACA,OAAOD,MAAM,CAACG,KAAK;EACrB,CAAC;AACH,CAAC;AAED,MAAMC,SAAS,GAAGC,OAAO,CAACC,QAAQ,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AC;AAEF,MAAM8D,QAAQ,GAAGA,CAAA,KAAM,CACrB,GAAG/B,kBAAkB,CAAC,CAAC,EACvB,GAAGM,iBAAiB,CAAC,CAAC,EACtB,GAAGE,mBAAmB,CAAC,CAAC,EACxB,GAAGK,kBAAkB,CAAC,CAAC,EACvB,GAAGC,kBAAkB,CAAC,CAAC,EACvB,GAAGC,iBAAiB,CAAC,CAAC,EACtB,GAAG3B,kBAAkB,CAAC,CAAC,EACvB3B,OAAO,CAACc,GAAG,CAAC,CAAC,CACd;;AAED;AACO,MAAMyD,aAAa,GAAIC,EAAU,IAAa;EACnD,OAAOxF,OAAO,CAAC6B,OAAO,CAAC2D,EAAE,EAAE;IAAEjD,KAAK,EAAE+C,QAAQ,CAAC;EAAE,CAAC,CAAC;AACnD,CAAC;AAACG,OAAA,CAAAF,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function toCommonJS(filename: string, code: string): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.toCommonJS = toCommonJS;
|
|
7
|
+
function _core() {
|
|
8
|
+
const data = require("@babel/core");
|
|
9
|
+
_core = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function toCommonJS(filename, code) {
|
|
15
|
+
const result = (0, _core().transformSync)(code, {
|
|
16
|
+
filename,
|
|
17
|
+
babelrc: false,
|
|
18
|
+
configFile: false,
|
|
19
|
+
plugins: [[require('@babel/plugin-transform-modules-commonjs'), {
|
|
20
|
+
// NOTE(@kitten): We used to use sucrase to transform, which is why
|
|
21
|
+
// we're doing this CJS-to-ESM transform in the first place. Our
|
|
22
|
+
// previous transformation isn't 100% compatible with the standard
|
|
23
|
+
// Node ESM loading. In Babel, this is the "node" flag (although
|
|
24
|
+
// node behaviour is explicitly different from this). This skips
|
|
25
|
+
// the `__esModule -> default` wrapper
|
|
26
|
+
importInterop: 'node',
|
|
27
|
+
loose: true
|
|
28
|
+
}]]
|
|
29
|
+
});
|
|
30
|
+
return result?.code ?? code;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.js","names":["_core","data","require","toCommonJS","filename","code","result","transformSync","babelrc","configFile","plugins","importInterop","loose"],"sources":["../src/transform.ts"],"sourcesContent":["import { transformSync } from '@babel/core';\n\nexport function toCommonJS(filename: string, code: string) {\n const result = transformSync(code, {\n filename,\n babelrc: false,\n configFile: false,\n plugins: [\n [\n require('@babel/plugin-transform-modules-commonjs'),\n {\n // NOTE(@kitten): We used to use sucrase to transform, which is why\n // we're doing this CJS-to-ESM transform in the first place. Our\n // previous transformation isn't 100% compatible with the standard\n // Node ESM loading. In Babel, this is the \"node\" flag (although\n // node behaviour is explicitly different from this). This skips\n // the `__esModule -> default` wrapper\n importInterop: 'node',\n loose: true,\n },\n ],\n ],\n });\n return result?.code ?? code;\n}\n"],"mappings":";;;;;;AAAA,SAAAA,MAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,KAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEO,SAASE,UAAUA,CAACC,QAAgB,EAAEC,IAAY,EAAE;EACzD,MAAMC,MAAM,GAAG,IAAAC,qBAAa,EAACF,IAAI,EAAE;IACjCD,QAAQ;IACRI,OAAO,EAAE,KAAK;IACdC,UAAU,EAAE,KAAK;IACjBC,OAAO,EAAE,CACP,CACER,OAAO,CAAC,0CAA0C,CAAC,EACnD;MACE;MACA;MACA;MACA;MACA;MACA;MACAS,aAAa,EAAE,MAAM;MACrBC,KAAK,EAAE;IACT,CAAC,CACF;EAEL,CAAC,CAAC;EACF,OAAON,MAAM,EAAED,IAAI,IAAIA,IAAI;AAC7B","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/require-utils",
|
|
3
|
-
"version": "55.0.
|
|
3
|
+
"version": "55.0.3-canary-20260424-7bedc9d",
|
|
4
4
|
"description": "Reusable require and Node resolution utilities library for Expo",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./build/index.js",
|
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
"clean": "expo-module clean",
|
|
14
14
|
"lint": "expo-module lint",
|
|
15
15
|
"generate": "node ./scripts/generate.js",
|
|
16
|
-
"
|
|
17
|
-
"prepublishOnly": "expo-module prepublishOnly",
|
|
16
|
+
"prepublishOnly": "pnpm run clean && pnpm run build",
|
|
18
17
|
"test": "expo-module test",
|
|
19
18
|
"typecheck": "expo-module typecheck"
|
|
20
19
|
},
|
|
@@ -28,7 +27,7 @@
|
|
|
28
27
|
"url": "https://github.com/expo/expo/issues"
|
|
29
28
|
},
|
|
30
29
|
"peerDependencies": {
|
|
31
|
-
"typescript": "^5.0.0 || ^5.0.0-0"
|
|
30
|
+
"typescript": "^5.0.0 || ^5.0.0-0 || ^6.0.0"
|
|
32
31
|
},
|
|
33
32
|
"peerDependenciesMeta": {
|
|
34
33
|
"typescript": {
|
|
@@ -36,15 +35,19 @@
|
|
|
36
35
|
}
|
|
37
36
|
},
|
|
38
37
|
"dependencies": {
|
|
39
|
-
"@babel/code-frame": "^7.20.0"
|
|
38
|
+
"@babel/code-frame": "^7.20.0",
|
|
39
|
+
"@babel/core": "^7.25.2",
|
|
40
|
+
"@babel/plugin-transform-modules-commonjs": "^7.24.8"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
43
|
+
"@babel/cli": "^7.23.4",
|
|
44
|
+
"@types/babel__core": "^7.20.5",
|
|
45
|
+
"@types/babel__code-frame": "^7.27.0",
|
|
42
46
|
"@types/node": "^22.14.0",
|
|
43
|
-
"expo-module-scripts": "
|
|
44
|
-
"
|
|
47
|
+
"expo-module-scripts": "workspace:*",
|
|
48
|
+
"memfs": "^3.2.0"
|
|
45
49
|
},
|
|
46
50
|
"publishConfig": {
|
|
47
51
|
"access": "public"
|
|
48
|
-
}
|
|
49
|
-
"gitHead": "22e2ad4afba05b91f833f8cf07a36637748a1f70"
|
|
52
|
+
}
|
|
50
53
|
}
|