@expo/require-utils 55.0.1 → 55.0.2
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/load.d.ts +2 -1
- package/build/load.js +51 -26
- package/build/load.js.map +1 -1
- package/build/transform.d.ts +1 -0
- package/build/transform.js +31 -0
- package/build/transform.js.map +1 -0
- package/package.json +6 -3
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,CAAC,EAAE;MACnD,MAAMK,IAAI,GAAGC,MAAM,CAACN,KAAK,CAAC,CAAC,CAAC,CAAC;MAC7B,OAAOM,MAAM,CAACC,aAAa,CAACF,IAAI,CAAC,GAAG;QAAEA,IAAI;QAAEG,MAAM,EAAEF,MAAM,CAACN,KAAK,CAAC,CAAC,CAAC,CAAC,IAA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B,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/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,6 +41,13 @@ 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
52
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
46
53
|
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; }
|
|
@@ -65,35 +72,35 @@ const tsExtensionMapping = {
|
|
|
65
72
|
'.cts': '.cjs',
|
|
66
73
|
'.mts': '.mjs'
|
|
67
74
|
};
|
|
68
|
-
function
|
|
75
|
+
function maybeReadFileSync(filename) {
|
|
76
|
+
try {
|
|
77
|
+
return _nodeFs().default.readFileSync(filename, 'utf8');
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (error.code === 'ENOENT') {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function toFormat(filename, isLegacy) {
|
|
69
86
|
if (filename.endsWith('.cjs')) {
|
|
70
87
|
return 'commonjs';
|
|
71
88
|
} else if (filename.endsWith('.mjs')) {
|
|
72
89
|
return 'module';
|
|
73
90
|
} else if (filename.endsWith('.js')) {
|
|
74
|
-
return
|
|
91
|
+
return isLegacy ? 'commonjs' : null;
|
|
75
92
|
} else if (filename.endsWith('.mts')) {
|
|
76
93
|
return 'module-typescript';
|
|
77
94
|
} else if (filename.endsWith('.cts')) {
|
|
78
95
|
return 'commonjs-typescript';
|
|
79
96
|
} else if (filename.endsWith('.ts')) {
|
|
80
|
-
return 'typescript';
|
|
97
|
+
return isLegacy ? 'commonjs-typescript' : 'typescript';
|
|
81
98
|
} else {
|
|
82
|
-
return
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
function isTypescriptFilename(filename) {
|
|
86
|
-
switch (toFormat(filename)) {
|
|
87
|
-
case 'module-typescript':
|
|
88
|
-
case 'commonjs-typescript':
|
|
89
|
-
case 'typescript':
|
|
90
|
-
return true;
|
|
91
|
-
default:
|
|
92
|
-
return false;
|
|
99
|
+
return null;
|
|
93
100
|
}
|
|
94
101
|
}
|
|
95
102
|
function compileModule(code, filename, opts) {
|
|
96
|
-
const format = toFormat(filename);
|
|
103
|
+
const format = toFormat(filename, false);
|
|
97
104
|
const prependPaths = opts.paths ?? [];
|
|
98
105
|
const nodeModulePaths = nodeModule()._nodeModulePaths(_nodePath().default.dirname(filename));
|
|
99
106
|
const paths = [...prependPaths, ...nodeModulePaths];
|
|
@@ -102,28 +109,28 @@ function compileModule(code, filename, opts) {
|
|
|
102
109
|
filename,
|
|
103
110
|
paths
|
|
104
111
|
});
|
|
105
|
-
mod._compile(code, filename, format);
|
|
112
|
+
mod._compile(code, filename, format != null ? format : undefined);
|
|
113
|
+
mod.loaded = true;
|
|
106
114
|
require.cache[filename] = mod;
|
|
107
115
|
parent?.children?.splice(parent.children.indexOf(mod), 1);
|
|
108
|
-
return mod
|
|
116
|
+
return mod;
|
|
109
117
|
} catch (error) {
|
|
110
118
|
delete require.cache[filename];
|
|
111
119
|
throw error;
|
|
112
120
|
}
|
|
113
121
|
}
|
|
114
122
|
const hasStripTypeScriptTypes = typeof nodeModule().stripTypeScriptTypes === 'function';
|
|
115
|
-
function evalModule(code, filename, opts = {}) {
|
|
123
|
+
function evalModule(code, filename, opts = {}, format = toFormat(filename, true)) {
|
|
116
124
|
let inputCode = code;
|
|
117
125
|
let inputFilename = filename;
|
|
118
126
|
let diagnostic;
|
|
119
|
-
if (
|
|
120
|
-
const ext = _nodePath().default.extname(filename);
|
|
127
|
+
if (format === 'typescript' || format === 'module-typescript' || format === 'commonjs-typescript') {
|
|
121
128
|
const ts = loadTypescript();
|
|
122
129
|
if (ts) {
|
|
123
130
|
let module;
|
|
124
|
-
if (
|
|
131
|
+
if (format === 'commonjs-typescript') {
|
|
125
132
|
module = ts.ModuleKind.CommonJS;
|
|
126
|
-
} else if (
|
|
133
|
+
} else if (format === 'module-typescript') {
|
|
127
134
|
module = ts.ModuleKind.ESNext;
|
|
128
135
|
} else {
|
|
129
136
|
// NOTE(@kitten): We can "preserve" the output, meaning, it can either be ESM or CJS
|
|
@@ -159,22 +166,29 @@ function evalModule(code, filename, opts = {}) {
|
|
|
159
166
|
});
|
|
160
167
|
}
|
|
161
168
|
if (inputCode !== code) {
|
|
169
|
+
const ext = _nodePath().default.extname(filename);
|
|
162
170
|
const inputExt = tsExtensionMapping[ext] ?? ext;
|
|
163
171
|
if (inputExt !== ext) {
|
|
164
172
|
inputFilename = _nodePath().default.join(_nodePath().default.dirname(filename), _nodePath().default.basename(filename, ext) + inputExt);
|
|
165
173
|
}
|
|
166
174
|
}
|
|
175
|
+
} else if (format === 'commonjs') {
|
|
176
|
+
inputCode = (0, _transform().toCommonJS)(filename, code);
|
|
167
177
|
}
|
|
168
178
|
try {
|
|
169
179
|
const mod = compileModule(inputCode, inputFilename, opts);
|
|
170
180
|
if (inputFilename !== filename) {
|
|
171
181
|
require.cache[filename] = mod;
|
|
172
182
|
}
|
|
173
|
-
return mod;
|
|
183
|
+
return mod.exports;
|
|
174
184
|
} catch (error) {
|
|
175
185
|
// If we have a diagnostic from TypeScript, we issue its error with a codeframe first,
|
|
176
186
|
// since it's likely more useful than the eval error
|
|
177
|
-
|
|
187
|
+
const diagnosticError = (0, _codeframe().formatDiagnostic)(diagnostic);
|
|
188
|
+
if (diagnosticError) {
|
|
189
|
+
throw diagnosticError;
|
|
190
|
+
}
|
|
191
|
+
throw (0, _codeframe().annotateError)(code, filename, error) ?? error;
|
|
178
192
|
}
|
|
179
193
|
}
|
|
180
194
|
async function requireOrImport(filename) {
|
|
@@ -200,19 +214,30 @@ async function loadModule(filename) {
|
|
|
200
214
|
* NOTE: Requiring ESM has been added in all LTS versions (Node 20.19+, 22.12+, 24).
|
|
201
215
|
* This already forms the minimum required Node version as of Expo SDK 54 */
|
|
202
216
|
function loadModuleSync(filename) {
|
|
217
|
+
const format = toFormat(filename, true);
|
|
218
|
+
const isTypeScript = format === 'module-typescript' || format === 'commonjs-typescript' || format === 'typescript';
|
|
203
219
|
try {
|
|
204
|
-
if (!
|
|
220
|
+
if (format !== 'module' && !isTypeScript) {
|
|
205
221
|
return require(filename);
|
|
206
222
|
}
|
|
207
223
|
} catch (error) {
|
|
208
224
|
if (error.code === 'MODULE_NOT_FOUND') {
|
|
209
225
|
throw error;
|
|
226
|
+
} else if (format == null) {
|
|
227
|
+
const code = maybeReadFileSync(filename);
|
|
228
|
+
throw (0, _codeframe().annotateError)(code, filename, error) || error;
|
|
210
229
|
}
|
|
211
230
|
// We fallback to always evaluating the entrypoint module
|
|
212
231
|
// This is out of safety, since we're not trusting the requiring ESM feature
|
|
213
232
|
// and evaluating the module manually bypasses the error when it's flagged off
|
|
214
233
|
}
|
|
234
|
+
|
|
235
|
+
// Load from cache manually, if `loaded` is set and exports are defined, to avoid
|
|
236
|
+
// double transform or double evaluation
|
|
237
|
+
if (require.cache[filename]?.exports && require.cache[filename].loaded) {
|
|
238
|
+
return require.cache[filename].exports;
|
|
239
|
+
}
|
|
215
240
|
const code = _nodeFs().default.readFileSync(filename, 'utf8');
|
|
216
|
-
return evalModule(code, filename);
|
|
241
|
+
return evalModule(code, filename, {}, format);
|
|
217
242
|
}
|
|
218
243
|
//# 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\nexport { evalMod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,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","_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","maybeReadFileSync","filename","fs","readFileSync","toFormat","isLegacy","endsWith","compileModule","opts","format","prependPaths","paths","nodeModulePaths","_nodeModulePaths","path","dirname","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","resolve","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 compileModule(code: string, filename: string, opts: ModuleOptions) {\n const format = toFormat(filename, false);\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 != 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(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AACwD,KAAK,CAACpB,QAAQ,CAAC,CAACmB,MAAM,EAAE;IACtE,OAAOvD,OAAO,CAACwD,KAAK,CAACpB,QAAQ,CAAC,CAAC8D,OAAO;EACxC;EAEA,MAAMnE,IAAI,GAAGM,iBAAE,CAACC,YAAY,CAACF,QAAQ,EAAE,MAAM,CAAC;EAC9C,OAAO0B,UAAU,CAAC/B,IAAI,EAAEK,QAAQ,EAAE,CAAC,CAAC,EAAEQ,MAAM,CAAC;AAC/C","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function toCommonJS(filename: string, code: string): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
plugins: [[require('@babel/plugin-transform-modules-commonjs'), {
|
|
19
|
+
// NOTE(@kitten): We used to use sucrase to transform, which is why
|
|
20
|
+
// we're doing this CJS-to-ESM transform in the first place. Our
|
|
21
|
+
// previous transformation isn't 100% compatible with the standard
|
|
22
|
+
// Node ESM loading. In Babel, this is the "node" flag (although
|
|
23
|
+
// node behaviour is explicitly different from this). This skips
|
|
24
|
+
// the `__esModule -> default` wrapper
|
|
25
|
+
importInterop: 'node',
|
|
26
|
+
loose: true
|
|
27
|
+
}]]
|
|
28
|
+
});
|
|
29
|
+
return result?.code ?? code;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.js","names":["_core","data","require","toCommonJS","filename","code","result","transformSync","babelrc","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 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,OAAO,EAAE,CACP,CACEP,OAAO,CAAC,0CAA0C,CAAC,EACnD;MACE;MACA;MACA;MACA;MACA;MACA;MACAQ,aAAa,EAAE,MAAM;MACrBC,KAAK,EAAE;IACT,CAAC,CACF;EAEL,CAAC,CAAC;EACF,OAAOL,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.2",
|
|
4
4
|
"description": "Reusable require and Node resolution utilities library for Expo",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./build/index.js",
|
|
@@ -36,15 +36,18 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@babel/code-frame": "^7.20.0"
|
|
39
|
+
"@babel/code-frame": "^7.20.0",
|
|
40
|
+
"@babel/core": "^7.25.2",
|
|
41
|
+
"@babel/plugin-transform-modules-commonjs": "^7.24.8"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
44
|
"@types/node": "^22.14.0",
|
|
43
45
|
"expo-module-scripts": "^55.0.2",
|
|
46
|
+
"memfs": "^3.2.0",
|
|
44
47
|
"typescript": "^5.9.2"
|
|
45
48
|
},
|
|
46
49
|
"publishConfig": {
|
|
47
50
|
"access": "public"
|
|
48
51
|
},
|
|
49
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "b183e5cbd95eb6ee54a878291c7077d8d63e4850"
|
|
50
53
|
}
|