@thomas.f/prnext 0.1.18-alpha → 0.1.20-alpha
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/README.md +2 -0
- package/build/actions.mjs +26 -14
- package/build/app.mjs +90 -101
- package/build/build-lock.mjs +2 -71
- package/build/build-retention.mjs +119 -0
- package/build/bundle-runtime.mjs +9 -8
- package/build/cache-command.mjs +31 -0
- package/build/check.mjs +41 -3
- package/build/compilation-cache.mjs +32 -12
- package/build/compilation-storage.mjs +190 -0
- package/build/compiler.mjs +8 -7
- package/build/config.mjs +25 -2
- package/build/create.mjs +1 -1
- package/build/css-modules.mjs +4 -0
- package/build/dev-action-graph.mjs +21 -0
- package/build/dev-css-assets.mjs +173 -0
- package/build/dev-css-update.mjs +14 -12
- package/build/dev-lazy-build.mjs +77 -0
- package/build/dynamic.mjs +13 -6
- package/build/font-cache.mjs +9 -6
- package/build/font-files.mjs +1 -1
- package/build/incremental.mjs +112 -18
- package/build/index.mjs +61 -15
- package/build/lazy-dynamic-imports.mjs +137 -0
- package/build/migrate.mjs +4 -4
- package/build/migration-audit.mjs +19 -31
- package/build/migration-imports.mjs +245 -0
- package/build/migration-scenarios-runner.mjs +73 -0
- package/build/migration-scenarios.mjs +72 -0
- package/build/native-discovery.mjs +65 -5
- package/build/native-packages.mjs +2 -0
- package/build/native-ppr.mjs +32 -0
- package/build/npm-packages.mjs +1 -0
- package/build/og.mjs +121 -1
- package/build/parallel-plan.mjs +55 -0
- package/build/persistent-cache.mjs +29 -24
- package/build/production-builder.mjs +1 -1
- package/build/production-check.mjs +34 -0
- package/build/react-compiler-report.mjs +31 -8
- package/build/react-compiler.mjs +101 -10
- package/build/server-config.mjs +35 -0
- package/build/source-analysis.mjs +54 -4
- package/build/standalone.mjs +21 -3
- package/build/static-adapter.mjs +7 -3
- package/build/transform.mjs +38 -6
- package/build/typescript-dev.mjs +3 -1
- package/build/webpack-graph.mjs +13 -3
- package/cli.mjs +24 -6
- package/compat/app-dynamic.cjs +12 -1
- package/compat/app-layout-context.cjs +7 -3
- package/compat/cache-handlers.cjs +3 -1
- package/compat/flight-delta.cjs +50 -13
- package/compat/index.d.ts +24 -1
- package/compat/link.cjs +2 -2
- package/compat/navigation-authorization.cjs +8 -1
- package/docs/ai/compatibility.md +187 -7
- package/docs/ai/deployment.md +141 -0
- package/docs/ai/quickstart.md +5 -0
- package/docs/ai/routing.md +11 -0
- package/docs/ai/troubleshooting.md +79 -0
- package/package.json +26 -11
- package/release/fontkit.mjs +31 -0
- package/release/verify.mjs +3 -0
- package/runtime/api.mjs +5 -2
- package/runtime/app-client.mjs +254 -53
- package/runtime/app-partial.mjs +2 -10
- package/runtime/app-prefetch.mjs +2 -2
- package/runtime/app-render.mjs +11 -7
- package/runtime/app-stream-channel.mjs +3 -2
- package/runtime/app-styles.mjs +22 -4
- package/runtime/atomic-file.mjs +27 -0
- package/runtime/cache-components-rsc.mjs +3 -1
- package/runtime/compile-cache-retention.mjs +53 -0
- package/runtime/compile-cache.mjs +28 -1
- package/runtime/dev-client.mjs +13 -5
- package/runtime/dev-file-changes.mjs +123 -8
- package/runtime/dev-gateway.mjs +3 -2
- package/runtime/dev-lazy-imports.mjs +121 -0
- package/runtime/dev-lazy-staging.mjs +14 -0
- package/runtime/dev-route-selection.mjs +64 -0
- package/runtime/dev-runtime-pool.mjs +3 -2
- package/runtime/dev-runtime-spare.mjs +1 -1
- package/runtime/dev-session-retention.mjs +154 -0
- package/runtime/dev-style-retention.mjs +15 -0
- package/runtime/development.mjs +86 -26
- package/runtime/env.mjs +9 -0
- package/runtime/flight-delta.mjs +59 -9
- package/runtime/fs.mjs +15 -8
- package/runtime/lazy-import-client.mjs +38 -0
- package/runtime/native-ppr.mjs +35 -0
- package/runtime/og/NOTICE.txt +1 -1
- package/runtime/og/index.node.mjs +76 -31216
- package/runtime/og/upstream.json +115 -0
- package/runtime/persistent/client.mjs +4 -2
- package/runtime/persistent/daemon.mjs +3 -11
- package/runtime/persistent/health.mjs +58 -0
- package/runtime/project-lock.mjs +71 -0
- package/runtime/request-transport.mjs +112 -32
- package/runtime/storage-path.mjs +36 -0
- package/runtime/trace.mjs +44 -4
- package/runtime/worker.mjs +9 -4
- package/vendor/fontkit/NOTICE.txt +5 -0
- package/vendor/fontkit/SOURCE-NOTICES.txt +209 -0
- package/vendor/fontkit/index.mjs +3 -0
- package/vendor/fontkit/licenses/@swc__helpers/LICENSE +201 -0
- package/vendor/fontkit/licenses/base64-js/LICENSE +21 -0
- package/vendor/fontkit/licenses/brotli/readme.md +61 -0
- package/vendor/fontkit/licenses/clone/LICENSE +18 -0
- package/vendor/fontkit/licenses/dfa/README.md +83 -0
- package/vendor/fontkit/licenses/fast-deep-equal/LICENSE +21 -0
- package/vendor/fontkit/licenses/fontkit/README.md +266 -0
- package/vendor/fontkit/licenses/restructure/LICENSE +21 -0
- package/vendor/fontkit/licenses/tiny-inflate/LICENSE +21 -0
- package/vendor/fontkit/licenses/tslib/LICENSE.txt +12 -0
- package/vendor/fontkit/licenses/unicode-properties/LICENSE +8 -0
- package/vendor/fontkit/licenses/unicode-trie/LICENSE +8 -0
- package/vendor/fontkit/upstream.json +215 -0
- package/vendor/nft/LICENSE +7 -0
- package/vendor/nft/README.md +16 -0
- package/vendor/nft/out/analyze.d.ts +8 -0
- package/vendor/nft/out/analyze.js +1216 -0
- package/vendor/nft/out/analyze.js.map +1 -0
- package/vendor/nft/out/cli.d.ts +2 -0
- package/vendor/nft/out/cli.js +94 -0
- package/vendor/nft/out/cli.js.map +1 -0
- package/vendor/nft/out/fs.d.ts +22 -0
- package/vendor/nft/out/fs.js +106 -0
- package/vendor/nft/out/fs.js.map +1 -0
- package/vendor/nft/out/index.d.ts +4 -0
- package/vendor/nft/out/index.js +25 -0
- package/vendor/nft/out/index.js.map +1 -0
- package/vendor/nft/out/node-file-trace.d.ts +41 -0
- package/vendor/nft/out/node-file-trace.js +380 -0
- package/vendor/nft/out/node-file-trace.js.map +1 -0
- package/vendor/nft/out/resolve-dependency.d.ts +6 -0
- package/vendor/nft/out/resolve-dependency.js +427 -0
- package/vendor/nft/out/resolve-dependency.js.map +1 -0
- package/vendor/nft/out/types.d.ts +66 -0
- package/vendor/nft/out/types.js +2 -0
- package/vendor/nft/out/types.js.map +1 -0
- package/vendor/nft/out/utils/ast-helpers.js +49 -0
- package/vendor/nft/out/utils/ast-helpers.js.map +1 -0
- package/vendor/nft/out/utils/binary-locators.js +88 -0
- package/vendor/nft/out/utils/binary-locators.js.map +1 -0
- package/vendor/nft/out/utils/get-package-base.js +30 -0
- package/vendor/nft/out/utils/get-package-base.js.map +1 -0
- package/vendor/nft/out/utils/interop-require.js +24 -0
- package/vendor/nft/out/utils/interop-require.js.map +1 -0
- package/vendor/nft/out/utils/node-version.js +10 -0
- package/vendor/nft/out/utils/node-version.js.map +1 -0
- package/vendor/nft/out/utils/sharedlib-emit.js +33 -0
- package/vendor/nft/out/utils/sharedlib-emit.js.map +1 -0
- package/vendor/nft/out/utils/special-cases.js +347 -0
- package/vendor/nft/out/utils/special-cases.js.map +1 -0
- package/vendor/nft/out/utils/static-eval.js +579 -0
- package/vendor/nft/out/utils/static-eval.js.map +1 -0
- package/vendor/nft/out/utils/types.js +2 -0
- package/vendor/nft/out/utils/types.js.map +1 -0
- package/vendor/nft/out/utils/wrappers.js +659 -0
- package/vendor/nft/out/utils/wrappers.js.map +1 -0
- package/vendor/nft/package.json +4 -0
- package/vendor/nft/upstream.json +51 -0
|
@@ -0,0 +1,1216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = analyze;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const estree_walker_1 = require("estree-walker");
|
|
9
|
+
const pluginutils_1 = require("@rollup/pluginutils");
|
|
10
|
+
const static_eval_1 = require("./utils/static-eval");
|
|
11
|
+
const acorn_1 = require("acorn");
|
|
12
|
+
const bindings_1 = __importDefault(require("bindings"));
|
|
13
|
+
const ast_helpers_1 = require("./utils/ast-helpers");
|
|
14
|
+
const glob_1 = require("glob");
|
|
15
|
+
const get_package_base_1 = require("./utils/get-package-base");
|
|
16
|
+
const binary_locators_1 = require("./utils/binary-locators");
|
|
17
|
+
const interop_require_1 = require("./utils/interop-require");
|
|
18
|
+
const special_cases_1 = __importDefault(require("./utils/special-cases"));
|
|
19
|
+
const resolve_dependency_js_1 = __importDefault(require("./resolve-dependency.js"));
|
|
20
|
+
//@ts-ignore
|
|
21
|
+
const node_gyp_build_1 = __importDefault(require("node-gyp-build"));
|
|
22
|
+
//@ts-ignore
|
|
23
|
+
const node_pre_gyp_1 = __importDefault(require("@mapbox/node-pre-gyp"));
|
|
24
|
+
const url_1 = require("url");
|
|
25
|
+
// Note: these should be deprecated over time as they ship in Acorn core
|
|
26
|
+
const acorn = acorn_1.Parser.extend(
|
|
27
|
+
//require("acorn-class-fields"),
|
|
28
|
+
//require("acorn-static-class-features"),
|
|
29
|
+
//require("acorn-private-class-elements")
|
|
30
|
+
require('acorn-import-attributes').importAttributesOrAssertions);
|
|
31
|
+
const os_1 = __importDefault(require("os"));
|
|
32
|
+
const url_2 = __importDefault(require("url"));
|
|
33
|
+
const wrappers_1 = require("./utils/wrappers");
|
|
34
|
+
const resolve_from_1 = __importDefault(require("resolve-from"));
|
|
35
|
+
const staticProcess = {
|
|
36
|
+
cwd: () => {
|
|
37
|
+
return cwd;
|
|
38
|
+
},
|
|
39
|
+
env: {
|
|
40
|
+
NODE_ENV: static_eval_1.UNKNOWN,
|
|
41
|
+
[static_eval_1.UNKNOWN]: true,
|
|
42
|
+
},
|
|
43
|
+
[static_eval_1.UNKNOWN]: true,
|
|
44
|
+
};
|
|
45
|
+
// unique symbol value to identify express instance in static analysis
|
|
46
|
+
const EXPRESS_SET = Symbol();
|
|
47
|
+
const EXPRESS_ENGINE = Symbol();
|
|
48
|
+
const NBIND_INIT = Symbol();
|
|
49
|
+
const SET_ROOT_DIR = Symbol();
|
|
50
|
+
const PINO_TRANSPORT = Symbol();
|
|
51
|
+
const FASTIFY_LOGGER = Symbol();
|
|
52
|
+
const PKG_INFO = Symbol();
|
|
53
|
+
const FS_FN = Symbol();
|
|
54
|
+
const FS_DIR_FN = Symbol();
|
|
55
|
+
const BINDINGS = Symbol();
|
|
56
|
+
const NODE_GYP_BUILD = Symbol();
|
|
57
|
+
const fsSymbols = {
|
|
58
|
+
access: FS_FN,
|
|
59
|
+
accessSync: FS_FN,
|
|
60
|
+
createReadStream: FS_FN,
|
|
61
|
+
exists: FS_FN,
|
|
62
|
+
existsSync: FS_FN,
|
|
63
|
+
fstat: FS_FN,
|
|
64
|
+
fstatSync: FS_FN,
|
|
65
|
+
lstat: FS_FN,
|
|
66
|
+
lstatSync: FS_FN,
|
|
67
|
+
open: FS_FN,
|
|
68
|
+
readdir: FS_DIR_FN,
|
|
69
|
+
readdirSync: FS_DIR_FN,
|
|
70
|
+
readFile: FS_FN,
|
|
71
|
+
readFileSync: FS_FN,
|
|
72
|
+
stat: FS_FN,
|
|
73
|
+
statSync: FS_FN,
|
|
74
|
+
};
|
|
75
|
+
const fsExtraSymbols = {
|
|
76
|
+
...fsSymbols,
|
|
77
|
+
pathExists: FS_FN,
|
|
78
|
+
pathExistsSync: FS_FN,
|
|
79
|
+
readJson: FS_FN,
|
|
80
|
+
readJSON: FS_FN,
|
|
81
|
+
readJsonSync: FS_FN,
|
|
82
|
+
readJSONSync: FS_FN,
|
|
83
|
+
};
|
|
84
|
+
const MODULE_FN = Symbol();
|
|
85
|
+
const CREATE_REQUIRE = Symbol();
|
|
86
|
+
const moduleSymbols = {
|
|
87
|
+
register: MODULE_FN,
|
|
88
|
+
createRequire: CREATE_REQUIRE,
|
|
89
|
+
};
|
|
90
|
+
const staticModules = Object.assign(Object.create(null), {
|
|
91
|
+
bindings: {
|
|
92
|
+
default: BINDINGS,
|
|
93
|
+
},
|
|
94
|
+
express: {
|
|
95
|
+
default: function () {
|
|
96
|
+
return {
|
|
97
|
+
[static_eval_1.UNKNOWN]: true,
|
|
98
|
+
set: EXPRESS_SET,
|
|
99
|
+
engine: EXPRESS_ENGINE,
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
fs: {
|
|
104
|
+
default: fsSymbols,
|
|
105
|
+
...fsSymbols,
|
|
106
|
+
},
|
|
107
|
+
module: {
|
|
108
|
+
default: moduleSymbols,
|
|
109
|
+
...moduleSymbols,
|
|
110
|
+
},
|
|
111
|
+
'fs-extra': {
|
|
112
|
+
default: fsExtraSymbols,
|
|
113
|
+
...fsExtraSymbols,
|
|
114
|
+
},
|
|
115
|
+
'graceful-fs': {
|
|
116
|
+
default: fsSymbols,
|
|
117
|
+
...fsSymbols,
|
|
118
|
+
},
|
|
119
|
+
process: {
|
|
120
|
+
default: staticProcess,
|
|
121
|
+
...staticProcess,
|
|
122
|
+
},
|
|
123
|
+
// populated below
|
|
124
|
+
path: {
|
|
125
|
+
default: {},
|
|
126
|
+
},
|
|
127
|
+
os: {
|
|
128
|
+
default: os_1.default,
|
|
129
|
+
...os_1.default,
|
|
130
|
+
},
|
|
131
|
+
url: {
|
|
132
|
+
default: url_2.default,
|
|
133
|
+
...url_2.default,
|
|
134
|
+
},
|
|
135
|
+
'@mapbox/node-pre-gyp': {
|
|
136
|
+
default: node_pre_gyp_1.default,
|
|
137
|
+
...node_pre_gyp_1.default,
|
|
138
|
+
},
|
|
139
|
+
'node-pre-gyp': binary_locators_1.pregyp,
|
|
140
|
+
'node-pre-gyp/lib/pre-binding': binary_locators_1.pregyp,
|
|
141
|
+
'node-pre-gyp/lib/pre-binding.js': binary_locators_1.pregyp,
|
|
142
|
+
'node-gyp-build': {
|
|
143
|
+
default: NODE_GYP_BUILD,
|
|
144
|
+
},
|
|
145
|
+
'@aminya/node-gyp-build': {
|
|
146
|
+
default: NODE_GYP_BUILD,
|
|
147
|
+
},
|
|
148
|
+
nbind: {
|
|
149
|
+
init: NBIND_INIT,
|
|
150
|
+
default: {
|
|
151
|
+
init: NBIND_INIT,
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
'resolve-from': {
|
|
155
|
+
default: resolve_from_1.default,
|
|
156
|
+
},
|
|
157
|
+
'strong-globalize': {
|
|
158
|
+
default: {
|
|
159
|
+
SetRootDir: SET_ROOT_DIR,
|
|
160
|
+
},
|
|
161
|
+
SetRootDir: SET_ROOT_DIR,
|
|
162
|
+
},
|
|
163
|
+
pkginfo: {
|
|
164
|
+
default: PKG_INFO,
|
|
165
|
+
},
|
|
166
|
+
pino: {
|
|
167
|
+
default: {
|
|
168
|
+
[static_eval_1.UNKNOWN]: true,
|
|
169
|
+
transport: PINO_TRANSPORT,
|
|
170
|
+
},
|
|
171
|
+
transport: PINO_TRANSPORT,
|
|
172
|
+
},
|
|
173
|
+
fastify: {
|
|
174
|
+
default: FASTIFY_LOGGER,
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
const globalBindings = {
|
|
178
|
+
// Support for require calls generated from `import` statements by babel
|
|
179
|
+
_interopRequireDefault: interop_require_1.normalizeDefaultRequire,
|
|
180
|
+
_interopRequireWildcard: interop_require_1.normalizeWildcardRequire,
|
|
181
|
+
// Support for require calls generated from `import` statements by tsc
|
|
182
|
+
__importDefault: interop_require_1.normalizeDefaultRequire,
|
|
183
|
+
__importStar: interop_require_1.normalizeWildcardRequire,
|
|
184
|
+
MONGOOSE_DRIVER_PATH: undefined,
|
|
185
|
+
URL: url_1.URL,
|
|
186
|
+
Object: {
|
|
187
|
+
assign: Object.assign,
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
globalBindings.global =
|
|
191
|
+
globalBindings.GLOBAL =
|
|
192
|
+
globalBindings.globalThis =
|
|
193
|
+
globalBindings;
|
|
194
|
+
// call expression triggers
|
|
195
|
+
const TRIGGER = Symbol();
|
|
196
|
+
binary_locators_1.pregyp.find[TRIGGER] = true;
|
|
197
|
+
const staticPath = staticModules.path;
|
|
198
|
+
Object.keys(path_1.default).forEach((name) => {
|
|
199
|
+
const pathFn = path_1.default[name];
|
|
200
|
+
if (typeof pathFn === 'function') {
|
|
201
|
+
const fn = function mockPath() {
|
|
202
|
+
return pathFn.apply(mockPath, arguments);
|
|
203
|
+
};
|
|
204
|
+
fn[TRIGGER] = true;
|
|
205
|
+
staticPath[name] = staticPath.default[name] = fn;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
staticPath[name] = staticPath.default[name] = pathFn;
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
// overload path.resolve to support custom cwd
|
|
212
|
+
staticPath.resolve = staticPath.default.resolve = function (...args) {
|
|
213
|
+
return path_1.default.resolve.apply(this, [cwd, ...args]);
|
|
214
|
+
};
|
|
215
|
+
staticPath.resolve[TRIGGER] = true;
|
|
216
|
+
const excludeAssetExtensions = new Set(['.h', '.cmake', '.c', '.cpp']);
|
|
217
|
+
const excludeAssetFiles = new Set([
|
|
218
|
+
'CHANGELOG.md',
|
|
219
|
+
'README.md',
|
|
220
|
+
'readme.md',
|
|
221
|
+
'changelog.md',
|
|
222
|
+
]);
|
|
223
|
+
let cwd;
|
|
224
|
+
const absoluteRegEx = /^\/[^\/]+|^[a-z]:[\\/][^\\/]+/i;
|
|
225
|
+
function isAbsolutePathOrUrl(str) {
|
|
226
|
+
if (str instanceof url_1.URL)
|
|
227
|
+
return str.protocol === 'file:';
|
|
228
|
+
if (typeof str === 'string') {
|
|
229
|
+
if (str.startsWith('file:')) {
|
|
230
|
+
try {
|
|
231
|
+
new url_1.URL(str);
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return absoluteRegEx.test(str);
|
|
239
|
+
}
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
const BOUND_REQUIRE = Symbol();
|
|
243
|
+
const repeatGlobRegEx = /([\/\\]\*\*[\/\\]\*)+/g;
|
|
244
|
+
// Helper: process pino transport config object
|
|
245
|
+
// Extracts target strings from { target: '...' }, { targets: [...] }, or { pipeline: [...] }
|
|
246
|
+
async function processPinoTransportObject(objNode, processRequireArg) {
|
|
247
|
+
for (const prop of objNode.properties) {
|
|
248
|
+
if (prop.type === 'Property' &&
|
|
249
|
+
!prop.computed &&
|
|
250
|
+
prop.key.type === 'Identifier') {
|
|
251
|
+
if (prop.key.name === 'target' && prop.value.type === 'Literal') {
|
|
252
|
+
await processRequireArg(prop.value);
|
|
253
|
+
}
|
|
254
|
+
else if ((prop.key.name === 'targets' || prop.key.name === 'pipeline') &&
|
|
255
|
+
prop.value.type === 'ArrayExpression') {
|
|
256
|
+
for (const el of prop.value.elements) {
|
|
257
|
+
if (el && el.type === 'ObjectExpression') {
|
|
258
|
+
for (const innerProp of el.properties) {
|
|
259
|
+
if (innerProp.type === 'Property' &&
|
|
260
|
+
!innerProp.computed &&
|
|
261
|
+
innerProp.key.type === 'Identifier' &&
|
|
262
|
+
innerProp.key.name === 'target' &&
|
|
263
|
+
innerProp.value.type === 'Literal') {
|
|
264
|
+
await processRequireArg(innerProp.value);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
async function analyze(id, code, job) {
|
|
274
|
+
const assets = new Set();
|
|
275
|
+
const deps = new Set();
|
|
276
|
+
const imports = new Set();
|
|
277
|
+
const dir = path_1.default.dirname(id);
|
|
278
|
+
// if (typeof options.production === 'boolean' && staticProcess.env.NODE_ENV === UNKNOWN)
|
|
279
|
+
// staticProcess.env.NODE_ENV = options.production ? 'production' : 'dev';
|
|
280
|
+
cwd = job.cwd;
|
|
281
|
+
const pkgBase = (0, get_package_base_1.getPackageBase)(id);
|
|
282
|
+
const emitAssetDirectory = (wildcardPath) => {
|
|
283
|
+
if (!job.analysis.emitGlobs)
|
|
284
|
+
return;
|
|
285
|
+
wildcardPath = wildcardPath.replaceAll(path_1.default.sep, path_1.default.posix.sep);
|
|
286
|
+
const wildcardIndex = wildcardPath.indexOf(static_eval_1.WILDCARD);
|
|
287
|
+
const dirIndex = wildcardIndex === -1
|
|
288
|
+
? wildcardPath.length
|
|
289
|
+
: wildcardPath.lastIndexOf(path_1.default.posix.sep, wildcardIndex);
|
|
290
|
+
const assetDirPath = wildcardPath.substring(0, dirIndex);
|
|
291
|
+
const patternPath = wildcardPath.slice(dirIndex);
|
|
292
|
+
const wildcardPattern = patternPath
|
|
293
|
+
.replace(static_eval_1.wildcardRegEx, (_match, index) => {
|
|
294
|
+
return patternPath[index - 1] === path_1.default.posix.sep ? '**/*' : '*';
|
|
295
|
+
})
|
|
296
|
+
.replace(repeatGlobRegEx, '/**/*') || '/**/*';
|
|
297
|
+
if (job.ignoreFn(path_1.default.relative(job.base, assetDirPath + wildcardPattern)))
|
|
298
|
+
return;
|
|
299
|
+
assetEmissionPromises = assetEmissionPromises.then(async () => {
|
|
300
|
+
if (job.log)
|
|
301
|
+
console.log('Globbing ' + assetDirPath + wildcardPattern);
|
|
302
|
+
const files = await (0, glob_1.glob)(assetDirPath + wildcardPattern, {
|
|
303
|
+
mark: true,
|
|
304
|
+
ignore: assetDirPath + '/**/node_modules/**/*',
|
|
305
|
+
dot: true,
|
|
306
|
+
nodir: true,
|
|
307
|
+
});
|
|
308
|
+
files
|
|
309
|
+
.filter((name) => !excludeAssetExtensions.has(path_1.default.extname(name)) &&
|
|
310
|
+
!excludeAssetFiles.has(path_1.default.basename(name)))
|
|
311
|
+
.forEach((file) => assets.add(file));
|
|
312
|
+
});
|
|
313
|
+
};
|
|
314
|
+
let assetEmissionPromises = Promise.resolve();
|
|
315
|
+
// remove shebang
|
|
316
|
+
code = code.replace(/^#![^\n\r]*[\r\n]/, '');
|
|
317
|
+
let ast;
|
|
318
|
+
let isESM = false;
|
|
319
|
+
try {
|
|
320
|
+
ast = acorn.parse(code, {
|
|
321
|
+
ecmaVersion: 'latest',
|
|
322
|
+
allowReturnOutsideFunction: true,
|
|
323
|
+
});
|
|
324
|
+
isESM = false;
|
|
325
|
+
}
|
|
326
|
+
catch (e) {
|
|
327
|
+
const isModule = e && e.message && e.message.includes('sourceType: module');
|
|
328
|
+
if (!isModule) {
|
|
329
|
+
job.warnings.add(new Error(`Failed to parse ${id} as script:\n${e && e.message}`));
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
//@ts-ignore
|
|
333
|
+
if (!ast) {
|
|
334
|
+
try {
|
|
335
|
+
ast = acorn.parse(code, {
|
|
336
|
+
ecmaVersion: 'latest',
|
|
337
|
+
sourceType: 'module',
|
|
338
|
+
allowAwaitOutsideFunction: true,
|
|
339
|
+
});
|
|
340
|
+
isESM = true;
|
|
341
|
+
}
|
|
342
|
+
catch (e) {
|
|
343
|
+
job.warnings.add(new Error(`Failed to parse ${id} as module:\n${e && e.message}`));
|
|
344
|
+
// Parser errors just skip analysis
|
|
345
|
+
return { assets, deps, imports, isESM: false };
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const importMetaUrl = (0, url_1.pathToFileURL)(id).href;
|
|
349
|
+
const knownBindings = Object.assign(Object.create(null), {
|
|
350
|
+
__dirname: {
|
|
351
|
+
shadowDepth: 0,
|
|
352
|
+
value: { value: path_1.default.resolve(id, '..') },
|
|
353
|
+
},
|
|
354
|
+
__filename: {
|
|
355
|
+
shadowDepth: 0,
|
|
356
|
+
value: { value: id },
|
|
357
|
+
},
|
|
358
|
+
process: {
|
|
359
|
+
shadowDepth: 0,
|
|
360
|
+
value: { value: staticProcess },
|
|
361
|
+
},
|
|
362
|
+
});
|
|
363
|
+
if (!isESM || job.mixedModules) {
|
|
364
|
+
knownBindings.require = {
|
|
365
|
+
shadowDepth: 0,
|
|
366
|
+
value: {
|
|
367
|
+
value: {
|
|
368
|
+
[static_eval_1.FUNCTION](specifier) {
|
|
369
|
+
deps.add(specifier);
|
|
370
|
+
const m = staticModules[specifier.startsWith('node:') ? specifier.slice(5) : specifier];
|
|
371
|
+
return m.default;
|
|
372
|
+
},
|
|
373
|
+
resolve(specifier) {
|
|
374
|
+
return (0, resolve_dependency_js_1.default)(specifier, id, job);
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
};
|
|
379
|
+
knownBindings.require.value.value.resolve[TRIGGER] = true;
|
|
380
|
+
}
|
|
381
|
+
function setKnownBinding(name, value) {
|
|
382
|
+
// require is somewhat special in that we shadow it but don't
|
|
383
|
+
// statically analyze it ("known unknown" of sorts)
|
|
384
|
+
// but we can make an exception for ones created by module.createRequire
|
|
385
|
+
if (name === 'require' &&
|
|
386
|
+
'value' in value &&
|
|
387
|
+
value.value !== BOUND_REQUIRE) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
knownBindings[name] = {
|
|
391
|
+
shadowDepth: 0,
|
|
392
|
+
value: value,
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
function getKnownBinding(name) {
|
|
396
|
+
const binding = knownBindings[name];
|
|
397
|
+
if (binding) {
|
|
398
|
+
if (binding.shadowDepth === 0) {
|
|
399
|
+
return binding.value;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return undefined;
|
|
403
|
+
}
|
|
404
|
+
function hasKnownBindingValue(name) {
|
|
405
|
+
const binding = knownBindings[name];
|
|
406
|
+
return binding && binding.shadowDepth === 0;
|
|
407
|
+
}
|
|
408
|
+
if ((isESM || job.mixedModules) && isAst(ast)) {
|
|
409
|
+
for (const decl of ast.body) {
|
|
410
|
+
if (decl.type === 'ImportDeclaration') {
|
|
411
|
+
const source = String(decl.source.value);
|
|
412
|
+
deps.add(source);
|
|
413
|
+
const staticModule = staticModules[source.startsWith('node:') ? source.slice(5) : source];
|
|
414
|
+
if (staticModule) {
|
|
415
|
+
for (const impt of decl.specifiers) {
|
|
416
|
+
if (impt.type === 'ImportNamespaceSpecifier')
|
|
417
|
+
setKnownBinding(impt.local.name, { value: staticModule });
|
|
418
|
+
else if (impt.type === 'ImportDefaultSpecifier' &&
|
|
419
|
+
'default' in staticModule)
|
|
420
|
+
setKnownBinding(impt.local.name, { value: staticModule.default });
|
|
421
|
+
else if (impt.type === 'ImportSpecifier' &&
|
|
422
|
+
impt.imported.name in staticModule)
|
|
423
|
+
setKnownBinding(impt.local.name, {
|
|
424
|
+
value: staticModule[impt.imported.name],
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
else if (decl.type === 'ExportNamedDeclaration' ||
|
|
430
|
+
decl.type === 'ExportAllDeclaration') {
|
|
431
|
+
if (decl.source)
|
|
432
|
+
deps.add(String(decl.source.value));
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
async function computePureStaticValue(expr, computeBranches = true) {
|
|
437
|
+
const vars = Object.create(null);
|
|
438
|
+
Object.keys(globalBindings).forEach((name) => {
|
|
439
|
+
vars[name] = { value: globalBindings[name] };
|
|
440
|
+
});
|
|
441
|
+
Object.keys(knownBindings).forEach((name) => {
|
|
442
|
+
vars[name] = getKnownBinding(name);
|
|
443
|
+
});
|
|
444
|
+
vars['import.meta'] = { url: importMetaUrl };
|
|
445
|
+
// evaluate returns undefined for non-statically-analyzable
|
|
446
|
+
const result = await (0, static_eval_1.evaluate)(expr, vars, computeBranches);
|
|
447
|
+
return result;
|
|
448
|
+
}
|
|
449
|
+
// statically determinable leaves are tracked, and inlined when the
|
|
450
|
+
// greatest parent statically known leaf computation corresponds to an asset path
|
|
451
|
+
let staticChildNode;
|
|
452
|
+
let staticChildValue;
|
|
453
|
+
// Express engine opt-out
|
|
454
|
+
let definedExpressEngines = false;
|
|
455
|
+
function emitWildcardRequire(wildcardRequire) {
|
|
456
|
+
if (!job.analysis.emitGlobs ||
|
|
457
|
+
(!wildcardRequire.startsWith('./') && !wildcardRequire.startsWith('../')))
|
|
458
|
+
return;
|
|
459
|
+
wildcardRequire = path_1.default
|
|
460
|
+
.resolve(dir, wildcardRequire)
|
|
461
|
+
.replaceAll(path_1.default.sep, path_1.default.posix.sep);
|
|
462
|
+
const wildcardIndex = wildcardRequire.indexOf(static_eval_1.WILDCARD);
|
|
463
|
+
const dirIndex = wildcardIndex === -1
|
|
464
|
+
? wildcardRequire.length
|
|
465
|
+
: wildcardRequire.lastIndexOf(path_1.default.posix.sep, wildcardIndex);
|
|
466
|
+
const wildcardDirPath = wildcardRequire.substring(0, dirIndex);
|
|
467
|
+
const patternPath = wildcardRequire.slice(dirIndex);
|
|
468
|
+
let wildcardPattern = patternPath.replace(static_eval_1.wildcardRegEx, (_match, index) => {
|
|
469
|
+
return patternPath[index - 1] === path_1.default.posix.sep ? '**/*' : '*';
|
|
470
|
+
}) || '/**/*';
|
|
471
|
+
if (!wildcardPattern.endsWith('*'))
|
|
472
|
+
wildcardPattern +=
|
|
473
|
+
'?(' + (job.ts ? '.ts|.tsx|' : '') + '.js|.json|.node)';
|
|
474
|
+
if (job.ignoreFn(path_1.default.relative(job.base, wildcardDirPath + wildcardPattern)))
|
|
475
|
+
return;
|
|
476
|
+
assetEmissionPromises = assetEmissionPromises.then(async () => {
|
|
477
|
+
if (job.log)
|
|
478
|
+
console.log('Globbing ' + wildcardDirPath + wildcardPattern);
|
|
479
|
+
const files = await (0, glob_1.glob)(wildcardDirPath + wildcardPattern, {
|
|
480
|
+
mark: true,
|
|
481
|
+
ignore: wildcardDirPath + '/**/node_modules/**/*',
|
|
482
|
+
nodir: true,
|
|
483
|
+
});
|
|
484
|
+
files
|
|
485
|
+
.filter((name) => !excludeAssetExtensions.has(path_1.default.extname(name)) &&
|
|
486
|
+
!excludeAssetFiles.has(path_1.default.basename(name)))
|
|
487
|
+
.forEach((file) => deps.add(file));
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
async function processRequireArg(expression, isImport = false) {
|
|
491
|
+
if (expression.type === 'ConditionalExpression') {
|
|
492
|
+
await processRequireArg(expression.consequent, isImport);
|
|
493
|
+
await processRequireArg(expression.alternate, isImport);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
if (expression.type === 'LogicalExpression') {
|
|
497
|
+
await processRequireArg(expression.left, isImport);
|
|
498
|
+
await processRequireArg(expression.right, isImport);
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
let computed = await computePureStaticValue(expression, true);
|
|
502
|
+
if (!computed)
|
|
503
|
+
return;
|
|
504
|
+
function add(value) {
|
|
505
|
+
(isImport ? imports : deps).add(value);
|
|
506
|
+
}
|
|
507
|
+
if ('value' in computed && typeof computed.value === 'string') {
|
|
508
|
+
if (!computed.wildcards)
|
|
509
|
+
add(computed.value);
|
|
510
|
+
else if (computed.wildcards.length >= 1)
|
|
511
|
+
emitWildcardRequire(computed.value);
|
|
512
|
+
}
|
|
513
|
+
else {
|
|
514
|
+
if ('ifTrue' in computed && typeof computed.ifTrue === 'string')
|
|
515
|
+
add(computed.ifTrue);
|
|
516
|
+
if ('else' in computed && typeof computed.else === 'string')
|
|
517
|
+
add(computed.else);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
let scope = (0, pluginutils_1.attachScopes)(ast, 'scope');
|
|
521
|
+
if (isAst(ast)) {
|
|
522
|
+
(0, wrappers_1.handleWrappers)(ast);
|
|
523
|
+
await (0, special_cases_1.default)({
|
|
524
|
+
id,
|
|
525
|
+
ast,
|
|
526
|
+
emitDependency: (path) => deps.add(path),
|
|
527
|
+
emitAsset: (path) => assets.add(path),
|
|
528
|
+
emitAssetDirectory,
|
|
529
|
+
job,
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
async function backtrack(parent, context) {
|
|
533
|
+
// computing a static expression outward
|
|
534
|
+
// -> compute and backtrack
|
|
535
|
+
// Note that `context` can be undefined in `leave()`
|
|
536
|
+
if (!staticChildNode)
|
|
537
|
+
throw new Error('Internal error: No staticChildNode for backtrack.');
|
|
538
|
+
const curStaticValue = await computePureStaticValue(parent, true);
|
|
539
|
+
if (curStaticValue) {
|
|
540
|
+
if (('value' in curStaticValue &&
|
|
541
|
+
typeof curStaticValue.value !== 'symbol') ||
|
|
542
|
+
('ifTrue' in curStaticValue &&
|
|
543
|
+
typeof curStaticValue.ifTrue !== 'symbol' &&
|
|
544
|
+
typeof curStaticValue.else !== 'symbol')) {
|
|
545
|
+
staticChildValue = curStaticValue;
|
|
546
|
+
staticChildNode = parent;
|
|
547
|
+
if (context)
|
|
548
|
+
context.skip();
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
// no static value -> see if we should emit the asset if it exists
|
|
553
|
+
await emitStaticChildAsset();
|
|
554
|
+
}
|
|
555
|
+
await (0, estree_walker_1.asyncWalk)(ast, {
|
|
556
|
+
async enter(_node, _parent) {
|
|
557
|
+
const node = _node;
|
|
558
|
+
const parent = _parent;
|
|
559
|
+
if (node.scope) {
|
|
560
|
+
scope = node.scope;
|
|
561
|
+
for (const id in node.scope.declarations) {
|
|
562
|
+
if (id in knownBindings)
|
|
563
|
+
knownBindings[id].shadowDepth++;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
// currently backtracking
|
|
567
|
+
if (staticChildNode)
|
|
568
|
+
return;
|
|
569
|
+
if (!parent)
|
|
570
|
+
return;
|
|
571
|
+
if (node.type === 'Identifier') {
|
|
572
|
+
if ((0, ast_helpers_1.isIdentifierRead)(node, parent) &&
|
|
573
|
+
job.analysis.computeFileReferences) {
|
|
574
|
+
let binding;
|
|
575
|
+
// detect asset leaf expression triggers (if not already)
|
|
576
|
+
// __dirname, __filename
|
|
577
|
+
if ((typeof (binding = getKnownBinding(node.name)?.value) === 'string' &&
|
|
578
|
+
binding.match(absoluteRegEx)) ||
|
|
579
|
+
(binding &&
|
|
580
|
+
(typeof binding === 'function' || typeof binding === 'object') &&
|
|
581
|
+
binding[TRIGGER])) {
|
|
582
|
+
staticChildValue = {
|
|
583
|
+
value: typeof binding === 'string' ? binding : undefined,
|
|
584
|
+
};
|
|
585
|
+
staticChildNode = node;
|
|
586
|
+
await backtrack(parent, this);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
else if (job.analysis.computeFileReferences &&
|
|
591
|
+
node.type === 'MemberExpression' &&
|
|
592
|
+
node.object.type === 'MetaProperty' &&
|
|
593
|
+
node.object.meta.name === 'import' &&
|
|
594
|
+
node.object.property.name === 'meta' &&
|
|
595
|
+
(node.property.computed ? node.property.value : node.property.name) ===
|
|
596
|
+
'url') {
|
|
597
|
+
// import.meta.url leaf trigger
|
|
598
|
+
staticChildValue = { value: importMetaUrl };
|
|
599
|
+
staticChildNode = node;
|
|
600
|
+
await backtrack(parent, this);
|
|
601
|
+
}
|
|
602
|
+
else if (node.type === 'ImportExpression') {
|
|
603
|
+
await processRequireArg(node.source, true);
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
// Call expression cases and asset triggers
|
|
607
|
+
// - fs triggers: fs.readFile(...)
|
|
608
|
+
// - require.resolve()
|
|
609
|
+
// - bindings()(...)
|
|
610
|
+
// - nodegyp()
|
|
611
|
+
// - etc.
|
|
612
|
+
else if (node.type === 'CallExpression') {
|
|
613
|
+
if ((!isESM || job.mixedModules) &&
|
|
614
|
+
node.callee.type === 'Identifier' &&
|
|
615
|
+
node.arguments.length) {
|
|
616
|
+
if (node.callee.name === 'require' &&
|
|
617
|
+
knownBindings.require &&
|
|
618
|
+
knownBindings.require.shadowDepth === 0) {
|
|
619
|
+
await processRequireArg(node.arguments[0]);
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
else if ((!isESM || job.mixedModules) &&
|
|
624
|
+
node.callee.type === 'MemberExpression' &&
|
|
625
|
+
node.callee.object.type === 'Identifier' &&
|
|
626
|
+
node.callee.object.name === 'module' &&
|
|
627
|
+
'module' in knownBindings === false &&
|
|
628
|
+
node.callee.property.type === 'Identifier' &&
|
|
629
|
+
!node.callee.computed &&
|
|
630
|
+
node.callee.property.name === 'require' &&
|
|
631
|
+
node.arguments.length) {
|
|
632
|
+
await processRequireArg(node.arguments[0]);
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
else if ((!isESM || job.mixedModules) &&
|
|
636
|
+
node.callee.type === 'MemberExpression' &&
|
|
637
|
+
node.callee.object.type === 'Identifier' &&
|
|
638
|
+
node.callee.object.name === 'require' &&
|
|
639
|
+
knownBindings.require &&
|
|
640
|
+
knownBindings.require.shadowDepth === 0 &&
|
|
641
|
+
node.callee.property.type === 'Identifier' &&
|
|
642
|
+
!node.callee.computed &&
|
|
643
|
+
node.callee.property.name === 'resolve' &&
|
|
644
|
+
node.arguments.length) {
|
|
645
|
+
await processRequireArg(node.arguments[0]);
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
const calleeValue = job.analysis.evaluatePureExpressions &&
|
|
649
|
+
(await computePureStaticValue(node.callee, false));
|
|
650
|
+
// if we have a direct pure static function,
|
|
651
|
+
// and that function has a [TRIGGER] symbol -> trigger asset emission from it
|
|
652
|
+
if (calleeValue &&
|
|
653
|
+
'value' in calleeValue &&
|
|
654
|
+
typeof calleeValue.value === 'function' &&
|
|
655
|
+
calleeValue.value[TRIGGER] &&
|
|
656
|
+
job.analysis.computeFileReferences) {
|
|
657
|
+
staticChildValue = await computePureStaticValue(node, true);
|
|
658
|
+
// if it computes, then we start backtracking
|
|
659
|
+
if (staticChildValue && parent) {
|
|
660
|
+
staticChildNode = node;
|
|
661
|
+
await backtrack(parent, this);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
// handle well-known function symbol cases
|
|
665
|
+
else if (calleeValue &&
|
|
666
|
+
'value' in calleeValue &&
|
|
667
|
+
typeof calleeValue.value === 'symbol') {
|
|
668
|
+
switch (calleeValue.value) {
|
|
669
|
+
// customRequireWrapper('...')
|
|
670
|
+
case BOUND_REQUIRE:
|
|
671
|
+
if (node.arguments.length === 1 &&
|
|
672
|
+
node.arguments[0].type === 'Literal' &&
|
|
673
|
+
node.callee.type === 'Identifier' &&
|
|
674
|
+
(!knownBindings.require ||
|
|
675
|
+
knownBindings.require.shadowDepth === 0)) {
|
|
676
|
+
await processRequireArg(node.arguments[0]);
|
|
677
|
+
}
|
|
678
|
+
break;
|
|
679
|
+
// require('bindings')(...)
|
|
680
|
+
case BINDINGS:
|
|
681
|
+
if (node.arguments.length) {
|
|
682
|
+
const arg = await computePureStaticValue(node.arguments[0], false);
|
|
683
|
+
if (arg && 'value' in arg && arg.value) {
|
|
684
|
+
let opts;
|
|
685
|
+
if (typeof arg.value === 'object')
|
|
686
|
+
opts = arg.value;
|
|
687
|
+
else if (typeof arg.value === 'string')
|
|
688
|
+
opts = { bindings: arg.value };
|
|
689
|
+
if (!opts.path) {
|
|
690
|
+
opts.path = true;
|
|
691
|
+
}
|
|
692
|
+
opts.module_root = pkgBase;
|
|
693
|
+
let resolved;
|
|
694
|
+
try {
|
|
695
|
+
resolved = (0, bindings_1.default)(opts);
|
|
696
|
+
}
|
|
697
|
+
catch (e) { }
|
|
698
|
+
if (resolved) {
|
|
699
|
+
staticChildValue = { value: resolved };
|
|
700
|
+
staticChildNode = node;
|
|
701
|
+
await emitStaticChildAsset();
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
break;
|
|
706
|
+
case NODE_GYP_BUILD:
|
|
707
|
+
// handle case: require('node-gyp-build')(__dirname)
|
|
708
|
+
// handle case: require('node-gyp-build')(join(__dirname, ''))
|
|
709
|
+
// also case: require('@aminya/node-gyp-build')(__dirname)
|
|
710
|
+
if (node.arguments.length) {
|
|
711
|
+
const arg = await computePureStaticValue(node.arguments[0], false);
|
|
712
|
+
if (arg && 'value' in arg && arg.value) {
|
|
713
|
+
const pathJoinedDir = arg.value;
|
|
714
|
+
let resolved;
|
|
715
|
+
try {
|
|
716
|
+
// the pkg could be 'node-gyp-build' or '@aminya/node-gyp-build'
|
|
717
|
+
const pkgName = node?.callee?.arguments?.[0]?.value || 'node-gyp-build';
|
|
718
|
+
// use installed version of node-gyp-build since resolving
|
|
719
|
+
// binaries can differ among versions
|
|
720
|
+
const nodeGypBuildPath = (0, resolve_from_1.default)(pathJoinedDir, pkgName);
|
|
721
|
+
resolved = require(nodeGypBuildPath).path(pathJoinedDir);
|
|
722
|
+
}
|
|
723
|
+
catch (e) {
|
|
724
|
+
try {
|
|
725
|
+
resolved = node_gyp_build_1.default.path(pathJoinedDir);
|
|
726
|
+
}
|
|
727
|
+
catch (e) { }
|
|
728
|
+
}
|
|
729
|
+
if (resolved) {
|
|
730
|
+
staticChildValue = { value: resolved };
|
|
731
|
+
staticChildNode = node;
|
|
732
|
+
await emitStaticChildAsset();
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
break;
|
|
737
|
+
// nbind.init(...) -> require('./resolved.node')
|
|
738
|
+
case NBIND_INIT:
|
|
739
|
+
if (node.arguments.length) {
|
|
740
|
+
const arg = await computePureStaticValue(node.arguments[0], false);
|
|
741
|
+
if (arg &&
|
|
742
|
+
'value' in arg &&
|
|
743
|
+
(typeof arg.value === 'string' ||
|
|
744
|
+
typeof arg.value === 'undefined')) {
|
|
745
|
+
const bindingInfo = (0, binary_locators_1.nbind)(arg.value);
|
|
746
|
+
if (bindingInfo && bindingInfo.path) {
|
|
747
|
+
deps.add(path_1.default.relative(dir, bindingInfo.path).replace(/\\/g, '/'));
|
|
748
|
+
return this.skip();
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
break;
|
|
753
|
+
// Express templates:
|
|
754
|
+
// app.set("view engine", [name]) -> 'name' is a require
|
|
755
|
+
case EXPRESS_SET:
|
|
756
|
+
if (node.arguments.length === 2 &&
|
|
757
|
+
node.arguments[0].type === 'Literal' &&
|
|
758
|
+
node.arguments[0].value === 'view engine' &&
|
|
759
|
+
!definedExpressEngines) {
|
|
760
|
+
await processRequireArg(node.arguments[1]);
|
|
761
|
+
return this.skip();
|
|
762
|
+
}
|
|
763
|
+
break;
|
|
764
|
+
// app.engine('name', ...) causes opt-out of express dynamic require
|
|
765
|
+
case EXPRESS_ENGINE:
|
|
766
|
+
definedExpressEngines = true;
|
|
767
|
+
break;
|
|
768
|
+
// pino.transport({ target: '...' }) or
|
|
769
|
+
// pino.transport({ targets: [{ target: '...' }] }) or
|
|
770
|
+
// pino.transport({ pipeline: [{ target: '...' }] })
|
|
771
|
+
case PINO_TRANSPORT:
|
|
772
|
+
if (node.arguments.length >= 1 &&
|
|
773
|
+
node.arguments[0].type === 'ObjectExpression') {
|
|
774
|
+
await processPinoTransportObject(node.arguments[0], processRequireArg);
|
|
775
|
+
return this.skip();
|
|
776
|
+
}
|
|
777
|
+
break;
|
|
778
|
+
// Fastify({ logger: { transport: { target: '...' } } })
|
|
779
|
+
case FASTIFY_LOGGER:
|
|
780
|
+
if (node.arguments.length >= 1 &&
|
|
781
|
+
node.arguments[0].type === 'ObjectExpression') {
|
|
782
|
+
for (const prop of node.arguments[0].properties) {
|
|
783
|
+
if (prop.type === 'Property' &&
|
|
784
|
+
!prop.computed &&
|
|
785
|
+
prop.key.type === 'Identifier' &&
|
|
786
|
+
prop.key.name === 'logger' &&
|
|
787
|
+
prop.value.type === 'ObjectExpression') {
|
|
788
|
+
for (const loggerProp of prop.value.properties) {
|
|
789
|
+
if (loggerProp.type === 'Property' &&
|
|
790
|
+
!loggerProp.computed &&
|
|
791
|
+
loggerProp.key.type === 'Identifier' &&
|
|
792
|
+
loggerProp.key.name === 'transport' &&
|
|
793
|
+
loggerProp.value.type === 'ObjectExpression') {
|
|
794
|
+
await processPinoTransportObject(loggerProp.value, processRequireArg);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
break;
|
|
801
|
+
case FS_FN:
|
|
802
|
+
case FS_DIR_FN:
|
|
803
|
+
if (node.arguments[0] && job.analysis.computeFileReferences) {
|
|
804
|
+
staticChildValue = await computePureStaticValue(node.arguments[0], true);
|
|
805
|
+
// if it computes, then we start backtracking
|
|
806
|
+
if (staticChildValue) {
|
|
807
|
+
staticChildNode = node.arguments[0];
|
|
808
|
+
if (calleeValue.value === FS_DIR_FN &&
|
|
809
|
+
node.arguments[0].type === 'Identifier' &&
|
|
810
|
+
node.arguments[0].name === '__dirname') {
|
|
811
|
+
// Special case `fs.readdirSync(__dirname)` to emit right away
|
|
812
|
+
emitAssetDirectory(dir);
|
|
813
|
+
}
|
|
814
|
+
else {
|
|
815
|
+
await backtrack(parent, this);
|
|
816
|
+
}
|
|
817
|
+
return this.skip();
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
break;
|
|
821
|
+
// strong globalize (emits intl folder)
|
|
822
|
+
case SET_ROOT_DIR:
|
|
823
|
+
if (node.arguments[0]) {
|
|
824
|
+
const rootDir = await computePureStaticValue(node.arguments[0], false);
|
|
825
|
+
if (rootDir && 'value' in rootDir && rootDir.value)
|
|
826
|
+
emitAssetDirectory(rootDir.value + '/intl');
|
|
827
|
+
return this.skip();
|
|
828
|
+
}
|
|
829
|
+
break;
|
|
830
|
+
// pkginfo - require('pkginfo')(module) -> loads package.json
|
|
831
|
+
case PKG_INFO:
|
|
832
|
+
let pjsonPath = path_1.default.resolve(id, '../package.json');
|
|
833
|
+
const rootPjson = path_1.default.resolve('/package.json');
|
|
834
|
+
while (pjsonPath !== rootPjson &&
|
|
835
|
+
(await job.stat(pjsonPath)) === null)
|
|
836
|
+
pjsonPath = path_1.default.resolve(pjsonPath, '../../package.json');
|
|
837
|
+
if (pjsonPath !== rootPjson)
|
|
838
|
+
assets.add(pjsonPath);
|
|
839
|
+
break;
|
|
840
|
+
case MODULE_FN:
|
|
841
|
+
if (node.arguments.length &&
|
|
842
|
+
// TODO: We only cater for the case where the first argument is a string
|
|
843
|
+
node.arguments[0].type === 'Literal') {
|
|
844
|
+
const pathOrSpecifier = node.arguments[0].value;
|
|
845
|
+
// It's a relative URL
|
|
846
|
+
if (pathOrSpecifier.startsWith('.')) {
|
|
847
|
+
// Compute the parentURL if it's statically analyzable
|
|
848
|
+
const computedParentURL = node.arguments.length > 1
|
|
849
|
+
? await computePureStaticValue(node.arguments[1])
|
|
850
|
+
: undefined;
|
|
851
|
+
if (computedParentURL && 'value' in computedParentURL) {
|
|
852
|
+
const parentURL = computedParentURL.value instanceof url_1.URL
|
|
853
|
+
? computedParentURL.value.href
|
|
854
|
+
: typeof computedParentURL.value === 'string'
|
|
855
|
+
? computedParentURL.value
|
|
856
|
+
: computedParentURL.value.parentURL;
|
|
857
|
+
// Resolve the srcURL from the parentURL
|
|
858
|
+
const srcURL = new url_1.URL(pathOrSpecifier, parentURL).href;
|
|
859
|
+
const currentDirURL = importMetaUrl.slice(0, importMetaUrl.lastIndexOf('/'));
|
|
860
|
+
// Resolve the srcPath relative to the current file
|
|
861
|
+
const srcPath = path_1.default.relative(currentDirURL, srcURL);
|
|
862
|
+
// Make it a proper relative path
|
|
863
|
+
const relativeSrcPath = srcPath.startsWith('.')
|
|
864
|
+
? srcPath
|
|
865
|
+
: './' + srcPath;
|
|
866
|
+
imports.add(relativeSrcPath);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
else {
|
|
870
|
+
// It's a bare specifier, so just add into the imports
|
|
871
|
+
imports.add(pathOrSpecifier);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
break;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
// Handle pino({ transport: { target: '...' } }) constructor pattern
|
|
878
|
+
// The callee (pino default export) evaluates to an object with
|
|
879
|
+
// transport: PINO_TRANSPORT, not a symbol, so the switch above misses it.
|
|
880
|
+
else if (calleeValue &&
|
|
881
|
+
'value' in calleeValue &&
|
|
882
|
+
typeof calleeValue.value === 'object' &&
|
|
883
|
+
calleeValue.value !== null &&
|
|
884
|
+
calleeValue.value.transport ===
|
|
885
|
+
PINO_TRANSPORT &&
|
|
886
|
+
node.arguments.length >= 1 &&
|
|
887
|
+
node.arguments[0].type === 'ObjectExpression') {
|
|
888
|
+
for (const prop of node.arguments[0].properties) {
|
|
889
|
+
if (prop.type === 'Property' &&
|
|
890
|
+
!prop.computed &&
|
|
891
|
+
prop.key.type === 'Identifier' &&
|
|
892
|
+
prop.key.name === 'transport' &&
|
|
893
|
+
prop.value.type === 'ObjectExpression') {
|
|
894
|
+
await processPinoTransportObject(prop.value, processRequireArg);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
else if (node.type === 'VariableDeclaration' &&
|
|
900
|
+
parent &&
|
|
901
|
+
!(0, ast_helpers_1.isVarLoop)(parent) &&
|
|
902
|
+
job.analysis.evaluatePureExpressions) {
|
|
903
|
+
for (const decl of node.declarations) {
|
|
904
|
+
if (!decl.init)
|
|
905
|
+
continue;
|
|
906
|
+
const computed = await computePureStaticValue(decl.init, true);
|
|
907
|
+
if (computed) {
|
|
908
|
+
// var known = ...;
|
|
909
|
+
if (decl.id.type === 'Identifier') {
|
|
910
|
+
setKnownBinding(decl.id.name, computed);
|
|
911
|
+
}
|
|
912
|
+
// var { known } = ...;
|
|
913
|
+
else if (decl.id.type === 'ObjectPattern' && 'value' in computed) {
|
|
914
|
+
for (const prop of decl.id.properties) {
|
|
915
|
+
if (prop.type !== 'Property' ||
|
|
916
|
+
prop.key.type !== 'Identifier' ||
|
|
917
|
+
prop.value.type !== 'Identifier' ||
|
|
918
|
+
typeof computed.value !== 'object' ||
|
|
919
|
+
computed.value === null ||
|
|
920
|
+
!(prop.key.name in computed.value))
|
|
921
|
+
continue;
|
|
922
|
+
setKnownBinding(prop.value.name, {
|
|
923
|
+
value: computed.value[prop.key.name],
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
if (!('value' in computed) &&
|
|
928
|
+
isAbsolutePathOrUrl(computed.ifTrue) &&
|
|
929
|
+
isAbsolutePathOrUrl(computed.else)) {
|
|
930
|
+
staticChildValue = computed;
|
|
931
|
+
staticChildNode = decl.init;
|
|
932
|
+
await emitStaticChildAsset();
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
else if (node.type === 'AssignmentExpression' &&
|
|
938
|
+
parent &&
|
|
939
|
+
!(0, ast_helpers_1.isLoop)(parent) &&
|
|
940
|
+
job.analysis.evaluatePureExpressions) {
|
|
941
|
+
if (!hasKnownBindingValue(node.left.name)) {
|
|
942
|
+
const computed = await computePureStaticValue(node.right, false);
|
|
943
|
+
if (computed && 'value' in computed) {
|
|
944
|
+
// var known = ...
|
|
945
|
+
if (node.left.type === 'Identifier') {
|
|
946
|
+
setKnownBinding(node.left.name, computed);
|
|
947
|
+
}
|
|
948
|
+
// var { known } = ...
|
|
949
|
+
else if (node.left.type === 'ObjectPattern') {
|
|
950
|
+
for (const prop of node.left.properties) {
|
|
951
|
+
if (prop.type !== 'Property' ||
|
|
952
|
+
prop.key.type !== 'Identifier' ||
|
|
953
|
+
prop.value.type !== 'Identifier' ||
|
|
954
|
+
typeof computed.value !== 'object' ||
|
|
955
|
+
computed.value === null ||
|
|
956
|
+
!(prop.key.name in computed.value))
|
|
957
|
+
continue;
|
|
958
|
+
setKnownBinding(prop.value.name, {
|
|
959
|
+
value: computed.value[prop.key.name],
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
if (isAbsolutePathOrUrl(computed.value)) {
|
|
964
|
+
staticChildValue = computed;
|
|
965
|
+
staticChildNode = node.right;
|
|
966
|
+
await emitStaticChildAsset();
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
// Support require wrappers like function p (x) { ...; var y = require(x); ...; return y; }
|
|
972
|
+
else if ((!isESM || job.mixedModules) &&
|
|
973
|
+
(node.type === 'FunctionDeclaration' ||
|
|
974
|
+
node.type === 'FunctionExpression' ||
|
|
975
|
+
node.type === 'ArrowFunctionExpression') &&
|
|
976
|
+
(node.arguments || node.params)[0] &&
|
|
977
|
+
(node.arguments || node.params)[0].type === 'Identifier') {
|
|
978
|
+
let fnName;
|
|
979
|
+
let args;
|
|
980
|
+
if ((node.type === 'ArrowFunctionExpression' ||
|
|
981
|
+
node.type === 'FunctionExpression') &&
|
|
982
|
+
parent &&
|
|
983
|
+
parent.type === 'VariableDeclarator' &&
|
|
984
|
+
parent.id.type === 'Identifier') {
|
|
985
|
+
fnName = parent.id;
|
|
986
|
+
args = node.arguments || node.params;
|
|
987
|
+
}
|
|
988
|
+
else if (node.id) {
|
|
989
|
+
fnName = node.id;
|
|
990
|
+
args = node.arguments || node.params;
|
|
991
|
+
}
|
|
992
|
+
if (fnName && node.body.body) {
|
|
993
|
+
let requireDecl, returned = false;
|
|
994
|
+
for (let i = 0; i < node.body.body.length; i++) {
|
|
995
|
+
if (node.body.body[i].type === 'VariableDeclaration' &&
|
|
996
|
+
!requireDecl) {
|
|
997
|
+
requireDecl = node.body.body[i].declarations.find((decl) => decl &&
|
|
998
|
+
decl.id &&
|
|
999
|
+
decl.id.type === 'Identifier' &&
|
|
1000
|
+
decl.init &&
|
|
1001
|
+
decl.init.type === 'CallExpression' &&
|
|
1002
|
+
decl.init.callee.type === 'Identifier' &&
|
|
1003
|
+
decl.init.callee.name === 'require' &&
|
|
1004
|
+
knownBindings.require.shadowDepth === 0 &&
|
|
1005
|
+
decl.init.arguments[0] &&
|
|
1006
|
+
decl.init.arguments[0].type === 'Identifier' &&
|
|
1007
|
+
decl.init.arguments[0].name === args[0].name);
|
|
1008
|
+
}
|
|
1009
|
+
if (requireDecl &&
|
|
1010
|
+
node.body.body[i].type === 'ReturnStatement' &&
|
|
1011
|
+
node.body.body[i].argument &&
|
|
1012
|
+
node.body.body[i].argument.type === 'Identifier' &&
|
|
1013
|
+
node.body.body[i].argument.name === requireDecl.id.name) {
|
|
1014
|
+
returned = true;
|
|
1015
|
+
break;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
if (returned)
|
|
1019
|
+
setKnownBinding(fnName.name, { value: BOUND_REQUIRE });
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
// Support module.createRequire
|
|
1023
|
+
if (node.type === 'CallExpression' &&
|
|
1024
|
+
node.callee.type === 'MemberExpression' &&
|
|
1025
|
+
node.callee.object.type === 'Identifier' &&
|
|
1026
|
+
node.callee.object.name === 'module' &&
|
|
1027
|
+
node.callee.property.type === 'Identifier' &&
|
|
1028
|
+
node.callee.property.name === 'createRequire') {
|
|
1029
|
+
if (parent.type === 'VariableDeclarator' &&
|
|
1030
|
+
parent.id.type === 'Identifier') {
|
|
1031
|
+
const requireName = parent.id.name;
|
|
1032
|
+
setKnownBinding(requireName, { value: BOUND_REQUIRE });
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
// Support createRequire from named import: import { createRequire } from 'node:module'
|
|
1036
|
+
if (node.type === 'CallExpression' &&
|
|
1037
|
+
node.callee.type === 'Identifier' &&
|
|
1038
|
+
node.callee.name === 'createRequire') {
|
|
1039
|
+
const createRequireBinding = getKnownBinding('createRequire');
|
|
1040
|
+
if (createRequireBinding &&
|
|
1041
|
+
'value' in createRequireBinding &&
|
|
1042
|
+
createRequireBinding.value === CREATE_REQUIRE) {
|
|
1043
|
+
if (parent.type === 'VariableDeclarator' &&
|
|
1044
|
+
parent.id.type === 'Identifier') {
|
|
1045
|
+
const requireName = parent.id.name;
|
|
1046
|
+
setKnownBinding(requireName, { value: BOUND_REQUIRE });
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
},
|
|
1051
|
+
async leave(_node, _parent) {
|
|
1052
|
+
const node = _node;
|
|
1053
|
+
const parent = _parent;
|
|
1054
|
+
if (node.scope) {
|
|
1055
|
+
if (scope.parent) {
|
|
1056
|
+
scope = scope.parent;
|
|
1057
|
+
}
|
|
1058
|
+
for (const id in node.scope.declarations) {
|
|
1059
|
+
if (id in knownBindings) {
|
|
1060
|
+
if (knownBindings[id].shadowDepth > 0)
|
|
1061
|
+
knownBindings[id].shadowDepth--;
|
|
1062
|
+
else
|
|
1063
|
+
delete knownBindings[id];
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
if (staticChildNode && parent)
|
|
1068
|
+
await backtrack(parent, this);
|
|
1069
|
+
},
|
|
1070
|
+
});
|
|
1071
|
+
await assetEmissionPromises;
|
|
1072
|
+
return { assets, deps, imports, isESM };
|
|
1073
|
+
async function emitAssetPath(assetPath) {
|
|
1074
|
+
// verify the asset file / directory exists
|
|
1075
|
+
const wildcardIndex = assetPath.indexOf(static_eval_1.WILDCARD);
|
|
1076
|
+
const dirIndex = wildcardIndex === -1
|
|
1077
|
+
? assetPath.length
|
|
1078
|
+
: assetPath.lastIndexOf(path_1.default.sep, wildcardIndex);
|
|
1079
|
+
const basePath = assetPath.substring(0, dirIndex);
|
|
1080
|
+
try {
|
|
1081
|
+
var stats = await job.stat(basePath);
|
|
1082
|
+
if (stats === null) {
|
|
1083
|
+
throw new Error('file not found');
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
catch (e) {
|
|
1087
|
+
return;
|
|
1088
|
+
}
|
|
1089
|
+
if (wildcardIndex !== -1 && stats.isFile())
|
|
1090
|
+
return;
|
|
1091
|
+
// do not emit assets outside the package boundary if inside node_modules
|
|
1092
|
+
if (pkgBase) {
|
|
1093
|
+
const nodeModulesBase = id.substring(0, id.indexOf(path_1.default.sep + 'node_modules')) +
|
|
1094
|
+
path_1.default.sep +
|
|
1095
|
+
'node_modules' +
|
|
1096
|
+
path_1.default.sep;
|
|
1097
|
+
if (!assetPath.startsWith(nodeModulesBase)) {
|
|
1098
|
+
if (job.log)
|
|
1099
|
+
console.log('Skipping asset emission of ' +
|
|
1100
|
+
assetPath +
|
|
1101
|
+
' for ' +
|
|
1102
|
+
id +
|
|
1103
|
+
' as it is outside the package base ' +
|
|
1104
|
+
pkgBase);
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
if (stats.isFile()) {
|
|
1109
|
+
// do not emit file assets outside job.base
|
|
1110
|
+
if (job.ignoreFn(path_1.default.relative(job.base, assetPath)))
|
|
1111
|
+
return;
|
|
1112
|
+
assets.add(assetPath);
|
|
1113
|
+
}
|
|
1114
|
+
else if (stats.isDirectory()) {
|
|
1115
|
+
// do not emit directory assets outside job.base
|
|
1116
|
+
if (job.ignoreFn(path_1.default.relative(job.base, assetPath)))
|
|
1117
|
+
return;
|
|
1118
|
+
if (validWildcard(assetPath))
|
|
1119
|
+
emitAssetDirectory(assetPath);
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
function validWildcard(assetPath) {
|
|
1123
|
+
let wildcardSuffix = '';
|
|
1124
|
+
if (assetPath.endsWith(path_1.default.sep))
|
|
1125
|
+
wildcardSuffix = path_1.default.sep;
|
|
1126
|
+
else if (assetPath.endsWith(path_1.default.sep + static_eval_1.WILDCARD))
|
|
1127
|
+
wildcardSuffix = path_1.default.sep + static_eval_1.WILDCARD;
|
|
1128
|
+
else if (assetPath.endsWith(static_eval_1.WILDCARD))
|
|
1129
|
+
wildcardSuffix = static_eval_1.WILDCARD;
|
|
1130
|
+
// do not emit __dirname
|
|
1131
|
+
if (assetPath === dir + wildcardSuffix)
|
|
1132
|
+
return false;
|
|
1133
|
+
// do not emit cwd
|
|
1134
|
+
if (assetPath === cwd + wildcardSuffix)
|
|
1135
|
+
return false;
|
|
1136
|
+
// do not emit node_modules
|
|
1137
|
+
if (assetPath.endsWith(path_1.default.sep + 'node_modules' + wildcardSuffix))
|
|
1138
|
+
return false;
|
|
1139
|
+
// do not emit directories above __dirname
|
|
1140
|
+
if (dir.startsWith(assetPath.slice(0, assetPath.length - wildcardSuffix.length) + path_1.default.sep))
|
|
1141
|
+
return false;
|
|
1142
|
+
// do not emit asset directories higher than the node_modules base if a package
|
|
1143
|
+
if (pkgBase) {
|
|
1144
|
+
const nodeModulesBase = id.substring(0, id.indexOf(path_1.default.sep + 'node_modules')) +
|
|
1145
|
+
path_1.default.sep +
|
|
1146
|
+
'node_modules' +
|
|
1147
|
+
path_1.default.sep;
|
|
1148
|
+
if (!assetPath.startsWith(nodeModulesBase)) {
|
|
1149
|
+
if (job.log)
|
|
1150
|
+
console.log('Skipping asset emission of ' +
|
|
1151
|
+
assetPath.replace(static_eval_1.wildcardRegEx, '*') +
|
|
1152
|
+
' for ' +
|
|
1153
|
+
id +
|
|
1154
|
+
' as it is outside the package base ' +
|
|
1155
|
+
pkgBase);
|
|
1156
|
+
return false;
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
return true;
|
|
1160
|
+
}
|
|
1161
|
+
function resolveAbsolutePathOrUrl(value) {
|
|
1162
|
+
return value instanceof url_1.URL
|
|
1163
|
+
? (0, url_1.fileURLToPath)(value)
|
|
1164
|
+
: value.startsWith('file:')
|
|
1165
|
+
? (0, url_1.fileURLToPath)(new url_1.URL(value))
|
|
1166
|
+
: path_1.default.resolve(value);
|
|
1167
|
+
}
|
|
1168
|
+
async function emitStaticChildAsset() {
|
|
1169
|
+
if (!staticChildValue) {
|
|
1170
|
+
return;
|
|
1171
|
+
}
|
|
1172
|
+
if ('value' in staticChildValue &&
|
|
1173
|
+
isAbsolutePathOrUrl(staticChildValue.value)) {
|
|
1174
|
+
try {
|
|
1175
|
+
const resolved = resolveAbsolutePathOrUrl(staticChildValue.value);
|
|
1176
|
+
await emitAssetPath(resolved);
|
|
1177
|
+
}
|
|
1178
|
+
catch (e) { }
|
|
1179
|
+
}
|
|
1180
|
+
else if ('ifTrue' in staticChildValue &&
|
|
1181
|
+
'else' in staticChildValue &&
|
|
1182
|
+
isAbsolutePathOrUrl(staticChildValue.ifTrue) &&
|
|
1183
|
+
isAbsolutePathOrUrl(staticChildValue.else)) {
|
|
1184
|
+
let resolvedThen;
|
|
1185
|
+
try {
|
|
1186
|
+
resolvedThen = resolveAbsolutePathOrUrl(staticChildValue.ifTrue);
|
|
1187
|
+
}
|
|
1188
|
+
catch (e) { }
|
|
1189
|
+
let resolvedElse;
|
|
1190
|
+
try {
|
|
1191
|
+
resolvedElse = resolveAbsolutePathOrUrl(staticChildValue.else);
|
|
1192
|
+
}
|
|
1193
|
+
catch (e) { }
|
|
1194
|
+
if (resolvedThen)
|
|
1195
|
+
await emitAssetPath(resolvedThen);
|
|
1196
|
+
if (resolvedElse)
|
|
1197
|
+
await emitAssetPath(resolvedElse);
|
|
1198
|
+
}
|
|
1199
|
+
else if (staticChildNode &&
|
|
1200
|
+
staticChildNode.type === 'ArrayExpression' &&
|
|
1201
|
+
'value' in staticChildValue &&
|
|
1202
|
+
staticChildValue.value instanceof Array) {
|
|
1203
|
+
for (const value of staticChildValue.value) {
|
|
1204
|
+
try {
|
|
1205
|
+
const resolved = resolveAbsolutePathOrUrl(value);
|
|
1206
|
+
await emitAssetPath(resolved);
|
|
1207
|
+
}
|
|
1208
|
+
catch (e) { }
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
staticChildNode = staticChildValue = undefined;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
function isAst(ast) {
|
|
1215
|
+
return 'body' in ast;
|
|
1216
|
+
}
|