@thomas.f/prnext 0.1.18-alpha → 0.1.19-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 +46 -25
- package/build/compiler.mjs +5 -4
- package/build/config.mjs +4 -2
- 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/incremental.mjs +112 -18
- package/build/index.mjs +32 -3
- 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/npm-packages.mjs +1 -0
- package/build/production-builder.mjs +1 -1
- package/build/standalone.mjs +21 -3
- package/build/webpack-graph.mjs +13 -3
- package/cli.mjs +10 -1
- package/compat/app-dynamic.cjs +12 -1
- package/compat/cache-handlers.cjs +3 -1
- package/compat/flight-delta.cjs +3 -1
- package/compat/index.d.ts +1 -1
- package/compat/link.cjs +2 -2
- package/docs/ai/compatibility.md +77 -0
- package/docs/ai/routing.md +11 -0
- package/docs/ai/troubleshooting.md +79 -0
- package/package.json +21 -9
- package/runtime/app-client.mjs +119 -42
- package/runtime/atomic-file.mjs +27 -0
- package/runtime/cache-components-rsc.mjs +3 -1
- package/runtime/dev-client.mjs +7 -2
- package/runtime/dev-file-changes.mjs +123 -8
- package/runtime/dev-lazy-imports.mjs +121 -0
- package/runtime/dev-lazy-staging.mjs +14 -0
- package/runtime/dev-style-retention.mjs +15 -0
- package/runtime/development.mjs +60 -19
- package/runtime/flight-delta.mjs +28 -4
- package/runtime/fs.mjs +15 -8
- package/runtime/lazy-import-client.mjs +38 -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,659 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleWrappers = handleWrappers;
|
|
4
|
+
const estree_walker_1 = require("estree-walker");
|
|
5
|
+
function isUndefinedOrVoid(node) {
|
|
6
|
+
return ((node.type === 'Identifier' && node.name === 'undefined') ||
|
|
7
|
+
(node.type === 'UnaryExpression' &&
|
|
8
|
+
node.operator === 'void' &&
|
|
9
|
+
node.argument.type === 'Literal' &&
|
|
10
|
+
node.argument.value === 0));
|
|
11
|
+
}
|
|
12
|
+
// Wrapper detection pretransforms to enable static analysis
|
|
13
|
+
function handleWrappers(ast) {
|
|
14
|
+
// UglifyJS will convert function wrappers into !function(){}
|
|
15
|
+
let wrapper;
|
|
16
|
+
if (ast.body.length === 1 &&
|
|
17
|
+
ast.body[0].type === 'ExpressionStatement' &&
|
|
18
|
+
ast.body[0].expression.type === 'UnaryExpression' &&
|
|
19
|
+
ast.body[0].expression.operator === '!' &&
|
|
20
|
+
ast.body[0].expression.argument.type === 'CallExpression' &&
|
|
21
|
+
ast.body[0].expression.argument.callee.type === 'FunctionExpression' &&
|
|
22
|
+
ast.body[0].expression.argument.arguments.length === 1)
|
|
23
|
+
wrapper = ast.body[0].expression.argument;
|
|
24
|
+
else if (ast.body.length === 1 &&
|
|
25
|
+
ast.body[0].type === 'ExpressionStatement' &&
|
|
26
|
+
ast.body[0].expression.type === 'CallExpression' &&
|
|
27
|
+
ast.body[0].expression.callee.type === 'FunctionExpression' &&
|
|
28
|
+
(ast.body[0].expression.arguments.length === 1 ||
|
|
29
|
+
ast.body[0].expression.arguments.length === 0))
|
|
30
|
+
wrapper = ast.body[0].expression;
|
|
31
|
+
else if (ast.body.length === 1 &&
|
|
32
|
+
ast.body[0].type === 'ExpressionStatement' &&
|
|
33
|
+
ast.body[0].expression.type === 'AssignmentExpression' &&
|
|
34
|
+
ast.body[0].expression.left.type === 'MemberExpression' &&
|
|
35
|
+
ast.body[0].expression.left.object.type === 'Identifier' &&
|
|
36
|
+
ast.body[0].expression.left.object.name === 'module' &&
|
|
37
|
+
ast.body[0].expression.left.property.type === 'Identifier' &&
|
|
38
|
+
ast.body[0].expression.left.property.name === 'exports' &&
|
|
39
|
+
ast.body[0].expression.right.type === 'CallExpression' &&
|
|
40
|
+
ast.body[0].expression.right.callee.type === 'FunctionExpression' &&
|
|
41
|
+
ast.body[0].expression.right.arguments.length === 1)
|
|
42
|
+
wrapper = ast.body[0].expression.right;
|
|
43
|
+
if (wrapper) {
|
|
44
|
+
let browserifyReturn;
|
|
45
|
+
let webpackModuleObj;
|
|
46
|
+
// When.js-style AMD wrapper:
|
|
47
|
+
// (function (define) { 'use strict' define(function (require) { ... }) })
|
|
48
|
+
// (typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); })
|
|
49
|
+
// ->
|
|
50
|
+
// (function (define) { 'use strict' define(function () { ... }) })
|
|
51
|
+
// (typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); })
|
|
52
|
+
if (wrapper.arguments[0] &&
|
|
53
|
+
wrapper.arguments[0].type === 'ConditionalExpression' &&
|
|
54
|
+
wrapper.arguments[0].test.type === 'LogicalExpression' &&
|
|
55
|
+
wrapper.arguments[0].test.operator === '&&' &&
|
|
56
|
+
wrapper.arguments[0].test.left.type === 'BinaryExpression' &&
|
|
57
|
+
wrapper.arguments[0].test.left.operator === '===' &&
|
|
58
|
+
wrapper.arguments[0].test.left.left.type === 'UnaryExpression' &&
|
|
59
|
+
wrapper.arguments[0].test.left.left.operator === 'typeof' &&
|
|
60
|
+
'name' in wrapper.arguments[0].test.left.left.argument &&
|
|
61
|
+
wrapper.arguments[0].test.left.left.argument.name === 'define' &&
|
|
62
|
+
wrapper.arguments[0].test.left.right.type === 'Literal' &&
|
|
63
|
+
wrapper.arguments[0].test.left.right.value === 'function' &&
|
|
64
|
+
wrapper.arguments[0].test.right.type === 'MemberExpression' &&
|
|
65
|
+
wrapper.arguments[0].test.right.object.type === 'Identifier' &&
|
|
66
|
+
wrapper.arguments[0].test.right.property.type === 'Identifier' &&
|
|
67
|
+
wrapper.arguments[0].test.right.property.name === 'amd' &&
|
|
68
|
+
wrapper.arguments[0].test.right.computed === false &&
|
|
69
|
+
wrapper.arguments[0].alternate.type === 'FunctionExpression' &&
|
|
70
|
+
wrapper.arguments[0].alternate.params.length === 1 &&
|
|
71
|
+
wrapper.arguments[0].alternate.params[0].type === 'Identifier' &&
|
|
72
|
+
wrapper.arguments[0].alternate.body.body.length === 1 &&
|
|
73
|
+
wrapper.arguments[0].alternate.body.body[0].type ===
|
|
74
|
+
'ExpressionStatement' &&
|
|
75
|
+
wrapper.arguments[0].alternate.body.body[0].expression.type ===
|
|
76
|
+
'AssignmentExpression' &&
|
|
77
|
+
wrapper.arguments[0].alternate.body.body[0].expression.left.type ===
|
|
78
|
+
'MemberExpression' &&
|
|
79
|
+
wrapper.arguments[0].alternate.body.body[0].expression.left.object
|
|
80
|
+
.type === 'Identifier' &&
|
|
81
|
+
wrapper.arguments[0].alternate.body.body[0].expression.left.object
|
|
82
|
+
.name === 'module' &&
|
|
83
|
+
wrapper.arguments[0].alternate.body.body[0].expression.left.property
|
|
84
|
+
.type === 'Identifier' &&
|
|
85
|
+
wrapper.arguments[0].alternate.body.body[0].expression.left.property
|
|
86
|
+
.name === 'exports' &&
|
|
87
|
+
wrapper.arguments[0].alternate.body.body[0].expression.left.computed ===
|
|
88
|
+
false &&
|
|
89
|
+
wrapper.arguments[0].alternate.body.body[0].expression.right.type ===
|
|
90
|
+
'CallExpression' &&
|
|
91
|
+
wrapper.arguments[0].alternate.body.body[0].expression.right.callee
|
|
92
|
+
.type === 'Identifier' &&
|
|
93
|
+
wrapper.arguments[0].alternate.body.body[0].expression.right.callee
|
|
94
|
+
.name === wrapper.arguments[0].alternate.params[0].name &&
|
|
95
|
+
'body' in wrapper.callee &&
|
|
96
|
+
'body' in wrapper.callee.body &&
|
|
97
|
+
Array.isArray(wrapper.callee.body.body) &&
|
|
98
|
+
wrapper.arguments[0].alternate.body.body[0].expression.right.arguments
|
|
99
|
+
.length === 1 &&
|
|
100
|
+
wrapper.arguments[0].alternate.body.body[0].expression.right.arguments[0]
|
|
101
|
+
.type === 'Identifier' &&
|
|
102
|
+
wrapper.arguments[0].alternate.body.body[0].expression.right.arguments[0]
|
|
103
|
+
.name === 'require') {
|
|
104
|
+
let body = wrapper.callee.body.body;
|
|
105
|
+
if (body[0].type === 'ExpressionStatement' &&
|
|
106
|
+
body[0].expression.type === 'Literal' &&
|
|
107
|
+
body[0].expression.value === 'use strict') {
|
|
108
|
+
body = body.slice(1);
|
|
109
|
+
}
|
|
110
|
+
if (body.length === 1 &&
|
|
111
|
+
body[0].type === 'ExpressionStatement' &&
|
|
112
|
+
body[0].expression.type === 'CallExpression' &&
|
|
113
|
+
body[0].expression.callee.type === 'Identifier' &&
|
|
114
|
+
body[0].expression.callee.name ===
|
|
115
|
+
wrapper.arguments[0].test.right.object.name &&
|
|
116
|
+
body[0].expression.arguments.length === 1 &&
|
|
117
|
+
body[0].expression.arguments[0].type === 'FunctionExpression' &&
|
|
118
|
+
body[0].expression.arguments[0].params.length === 1 &&
|
|
119
|
+
body[0].expression.arguments[0].params[0].type === 'Identifier' &&
|
|
120
|
+
body[0].expression.arguments[0].params[0].name === 'require') {
|
|
121
|
+
const arg = body[0].expression.arguments[0];
|
|
122
|
+
arg.params = [];
|
|
123
|
+
try {
|
|
124
|
+
// @ts-ignore If it doesn't exist that's ok
|
|
125
|
+
delete arg.scope.declarations.require;
|
|
126
|
+
}
|
|
127
|
+
catch (e) { }
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// Browserify-style wrapper
|
|
131
|
+
// (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.bugsnag = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({
|
|
132
|
+
// 1:[function(require,module,exports){
|
|
133
|
+
// ...code...
|
|
134
|
+
// },{"external":undefined}], 2: ...
|
|
135
|
+
// },{},[24])(24)
|
|
136
|
+
// });
|
|
137
|
+
// ->
|
|
138
|
+
// (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.bugsnag = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({
|
|
139
|
+
// 1:[function(require,module,exports){
|
|
140
|
+
// ...code...
|
|
141
|
+
// },{"external":undefined}], 2: ...
|
|
142
|
+
// },{
|
|
143
|
+
// "external": { exports: require('external') }
|
|
144
|
+
// },[24])(24)
|
|
145
|
+
// });
|
|
146
|
+
else if (wrapper.arguments[0] &&
|
|
147
|
+
wrapper.arguments[0].type === 'FunctionExpression' &&
|
|
148
|
+
wrapper.arguments[0].params.length === 0 &&
|
|
149
|
+
(wrapper.arguments[0].body.body.length === 1 ||
|
|
150
|
+
(wrapper.arguments[0].body.body.length === 2 &&
|
|
151
|
+
wrapper.arguments[0].body.body[0].type === 'VariableDeclaration' &&
|
|
152
|
+
wrapper.arguments[0].body.body[0].declarations.length === 3 &&
|
|
153
|
+
wrapper.arguments[0].body.body[0].declarations.every((decl) => decl.init === null && decl.id.type === 'Identifier'))) &&
|
|
154
|
+
wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1]
|
|
155
|
+
.type === 'ReturnStatement' &&
|
|
156
|
+
(browserifyReturn = wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1]) &&
|
|
157
|
+
browserifyReturn.argument?.type === 'CallExpression' &&
|
|
158
|
+
browserifyReturn.argument.arguments.length &&
|
|
159
|
+
browserifyReturn.argument.arguments.every((arg) => arg && arg.type === 'Literal' && typeof arg.value === 'number') &&
|
|
160
|
+
browserifyReturn.argument.callee.type === 'CallExpression' &&
|
|
161
|
+
(browserifyReturn.argument.callee.callee.type === 'FunctionExpression' ||
|
|
162
|
+
(browserifyReturn.argument.callee.callee.type === 'CallExpression' &&
|
|
163
|
+
browserifyReturn.argument.callee.callee.callee.type ===
|
|
164
|
+
'FunctionExpression' &&
|
|
165
|
+
browserifyReturn.argument.callee.callee.arguments.length === 0)) &&
|
|
166
|
+
// (dont go deeper into browserify loader internals than this)
|
|
167
|
+
browserifyReturn.argument.callee.arguments.length === 3 &&
|
|
168
|
+
browserifyReturn.argument.callee.arguments[0].type ===
|
|
169
|
+
'ObjectExpression' &&
|
|
170
|
+
browserifyReturn.argument.callee.arguments[1].type ===
|
|
171
|
+
'ObjectExpression' &&
|
|
172
|
+
browserifyReturn.argument.callee.arguments[2].type === 'ArrayExpression') {
|
|
173
|
+
const modules = browserifyReturn.argument.callee.arguments[0].properties;
|
|
174
|
+
// verify modules is the expected data structure
|
|
175
|
+
// in the process, extract external requires
|
|
176
|
+
const externals = {};
|
|
177
|
+
if (modules.every((m) => {
|
|
178
|
+
if (m.type !== 'Property' ||
|
|
179
|
+
m.computed !== false ||
|
|
180
|
+
m.key.type !== 'Literal' ||
|
|
181
|
+
typeof m.key.value !== 'number' ||
|
|
182
|
+
m.value.type !== 'ArrayExpression' ||
|
|
183
|
+
m.value.elements.length !== 2 ||
|
|
184
|
+
!m.value.elements[0] ||
|
|
185
|
+
!m.value.elements[1] ||
|
|
186
|
+
m.value.elements[0].type !== 'FunctionExpression' ||
|
|
187
|
+
m.value.elements[1].type !== 'ObjectExpression') {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
// detect externals from undefined moduleMap values
|
|
191
|
+
const moduleMap = m.value.elements[1].properties;
|
|
192
|
+
for (const prop of moduleMap) {
|
|
193
|
+
if (prop.type !== 'Property' ||
|
|
194
|
+
(prop.value.type !== 'Identifier' &&
|
|
195
|
+
prop.value.type !== 'Literal' &&
|
|
196
|
+
!isUndefinedOrVoid(prop.value)) ||
|
|
197
|
+
!((prop.key.type === 'Literal' &&
|
|
198
|
+
typeof prop.key.value === 'string') ||
|
|
199
|
+
prop.key.type === 'Identifier') ||
|
|
200
|
+
prop.computed) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
if (isUndefinedOrVoid(prop.value)) {
|
|
204
|
+
if (prop.key.type === 'Identifier') {
|
|
205
|
+
externals[prop.key.name] = {
|
|
206
|
+
type: 'Literal',
|
|
207
|
+
// @ts-ignore start can be undefined
|
|
208
|
+
start: prop.key.start,
|
|
209
|
+
// @ts-ignore end can be undefined
|
|
210
|
+
end: prop.key.end,
|
|
211
|
+
value: prop.key.name,
|
|
212
|
+
raw: JSON.stringify(prop.key.name),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
else if (prop.key.type === 'Literal') {
|
|
216
|
+
externals[String(prop.key.value)] = prop.key;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return true;
|
|
221
|
+
})) {
|
|
222
|
+
// if we have externals, inline them into the browserify cache for webpack to pick up
|
|
223
|
+
const externalIds = Object.keys(externals);
|
|
224
|
+
const cache = browserifyReturn.argument.callee.arguments[1];
|
|
225
|
+
cache.properties = externalIds.map((ext) => {
|
|
226
|
+
return {
|
|
227
|
+
type: 'Property',
|
|
228
|
+
method: false,
|
|
229
|
+
shorthand: false,
|
|
230
|
+
computed: false,
|
|
231
|
+
kind: 'init',
|
|
232
|
+
key: externals[ext],
|
|
233
|
+
value: {
|
|
234
|
+
type: 'ObjectExpression',
|
|
235
|
+
properties: [
|
|
236
|
+
{
|
|
237
|
+
type: 'Property',
|
|
238
|
+
kind: 'init',
|
|
239
|
+
method: false,
|
|
240
|
+
shorthand: false,
|
|
241
|
+
computed: false,
|
|
242
|
+
key: {
|
|
243
|
+
type: 'Identifier',
|
|
244
|
+
name: 'exports',
|
|
245
|
+
},
|
|
246
|
+
value: {
|
|
247
|
+
type: 'CallExpression',
|
|
248
|
+
optional: false,
|
|
249
|
+
callee: {
|
|
250
|
+
type: 'Identifier',
|
|
251
|
+
name: 'require',
|
|
252
|
+
},
|
|
253
|
+
arguments: [externals[ext]],
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
],
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// UMD wrapper
|
|
263
|
+
// (function (factory) {
|
|
264
|
+
// if (typeof module === "object" && typeof module.exports === "object") {
|
|
265
|
+
// var v = factory(require, exports);
|
|
266
|
+
// if (v !== undefined) module.exports = v;
|
|
267
|
+
// }
|
|
268
|
+
// else if (typeof define === "function" && define.amd) {
|
|
269
|
+
// define(["require", "exports", "./impl/format", "./impl/edit", "./impl/scanner", "./impl/parser"], factory);
|
|
270
|
+
// }
|
|
271
|
+
// })(function (require, exports) {
|
|
272
|
+
// // ...
|
|
273
|
+
// }
|
|
274
|
+
// ->
|
|
275
|
+
// (function (factory) {
|
|
276
|
+
// if (typeof module === "object" && typeof module.exports === "object") {
|
|
277
|
+
// var v = factory(require, exports);
|
|
278
|
+
// if (v !== undefined) module.exports = v;
|
|
279
|
+
// }
|
|
280
|
+
// else if (typeof define === "function" && define.amd) {
|
|
281
|
+
// define(["require", "exports", "./impl/format", "./impl/edit", "./impl/scanner", "./impl/parser"], factory);
|
|
282
|
+
// }
|
|
283
|
+
// })(function () {
|
|
284
|
+
// // ...
|
|
285
|
+
// }
|
|
286
|
+
else if (wrapper.arguments[0] &&
|
|
287
|
+
wrapper.arguments[0].type === 'FunctionExpression' &&
|
|
288
|
+
wrapper.arguments[0].params.length === 2 &&
|
|
289
|
+
wrapper.arguments[0].params[0].type === 'Identifier' &&
|
|
290
|
+
wrapper.arguments[0].params[1].type === 'Identifier' &&
|
|
291
|
+
'body' in wrapper.callee &&
|
|
292
|
+
'body' in wrapper.callee.body &&
|
|
293
|
+
Array.isArray(wrapper.callee.body.body) &&
|
|
294
|
+
wrapper.callee.body.body.length === 1) {
|
|
295
|
+
const statement = wrapper.callee.body.body[0];
|
|
296
|
+
if (statement.type === 'IfStatement' &&
|
|
297
|
+
statement.test.type === 'LogicalExpression' &&
|
|
298
|
+
statement.test.operator === '&&' &&
|
|
299
|
+
statement.test.left.type === 'BinaryExpression' &&
|
|
300
|
+
statement.test.left.left.type === 'UnaryExpression' &&
|
|
301
|
+
statement.test.left.left.operator === 'typeof' &&
|
|
302
|
+
statement.test.left.left.argument.type === 'Identifier' &&
|
|
303
|
+
statement.test.left.left.argument.name === 'module' &&
|
|
304
|
+
statement.test.left.right.type === 'Literal' &&
|
|
305
|
+
statement.test.left.right.value === 'object' &&
|
|
306
|
+
statement.test.right.type === 'BinaryExpression' &&
|
|
307
|
+
statement.test.right.left.type === 'UnaryExpression' &&
|
|
308
|
+
statement.test.right.left.operator === 'typeof' &&
|
|
309
|
+
statement.test.right.left.argument.type === 'MemberExpression' &&
|
|
310
|
+
statement.test.right.left.argument.object.type === 'Identifier' &&
|
|
311
|
+
statement.test.right.left.argument.object.name === 'module' &&
|
|
312
|
+
statement.test.right.left.argument.property.type === 'Identifier' &&
|
|
313
|
+
statement.test.right.left.argument.property.name === 'exports' &&
|
|
314
|
+
statement.test.right.right.type === 'Literal' &&
|
|
315
|
+
statement.test.right.right.value === 'object' &&
|
|
316
|
+
statement.consequent.type === 'BlockStatement' &&
|
|
317
|
+
statement.consequent.body.length > 0) {
|
|
318
|
+
let callSite;
|
|
319
|
+
if (statement.consequent.body[0].type === 'VariableDeclaration' &&
|
|
320
|
+
statement.consequent.body[0].declarations[0].init &&
|
|
321
|
+
statement.consequent.body[0].declarations[0].init.type ===
|
|
322
|
+
'CallExpression')
|
|
323
|
+
callSite = statement.consequent.body[0].declarations[0].init;
|
|
324
|
+
else if (statement.consequent.body[0].type === 'ExpressionStatement' &&
|
|
325
|
+
statement.consequent.body[0].expression.type === 'CallExpression')
|
|
326
|
+
callSite = statement.consequent.body[0].expression;
|
|
327
|
+
else if (statement.consequent.body[0].type === 'ExpressionStatement' &&
|
|
328
|
+
statement.consequent.body[0].expression.type ===
|
|
329
|
+
'AssignmentExpression' &&
|
|
330
|
+
statement.consequent.body[0].expression.operator === '=' &&
|
|
331
|
+
statement.consequent.body[0].expression.right.type ===
|
|
332
|
+
'CallExpression')
|
|
333
|
+
callSite = statement.consequent.body[0].expression.right;
|
|
334
|
+
if (callSite &&
|
|
335
|
+
callSite.callee.type === 'Identifier' &&
|
|
336
|
+
'params' in wrapper.callee &&
|
|
337
|
+
wrapper.callee.params.length > 0 &&
|
|
338
|
+
'name' in wrapper.callee.params[0] &&
|
|
339
|
+
callSite.callee.name === wrapper.callee.params[0].name &&
|
|
340
|
+
callSite.arguments.length === 2 &&
|
|
341
|
+
callSite.arguments[0].type === 'Identifier' &&
|
|
342
|
+
callSite.arguments[0].name === 'require' &&
|
|
343
|
+
callSite.arguments[1].type === 'Identifier' &&
|
|
344
|
+
callSite.arguments[1].name === 'exports') {
|
|
345
|
+
const funcExpression = wrapper.arguments[0];
|
|
346
|
+
funcExpression.params = [];
|
|
347
|
+
try {
|
|
348
|
+
// @ts-ignore If scope doesn't exist that's ok
|
|
349
|
+
const scope = funcExpression.scope;
|
|
350
|
+
delete scope.declarations.require;
|
|
351
|
+
delete scope.declarations.exports;
|
|
352
|
+
}
|
|
353
|
+
catch (e) { }
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
// Webpack wrapper
|
|
358
|
+
//
|
|
359
|
+
// module.exports = (function(e) {
|
|
360
|
+
// var t = {};
|
|
361
|
+
// function r(n) { /*...*/ }
|
|
362
|
+
// })([
|
|
363
|
+
// function (e, t) {
|
|
364
|
+
// e.exports = require("fs");
|
|
365
|
+
// },
|
|
366
|
+
// function(e, t, r) {
|
|
367
|
+
// const n = r(0);
|
|
368
|
+
// const ns = r.n(n);
|
|
369
|
+
// ns.a.export;
|
|
370
|
+
// }
|
|
371
|
+
// ]);
|
|
372
|
+
// ->
|
|
373
|
+
// module.exports = (function(e) {
|
|
374
|
+
// var t = {};
|
|
375
|
+
// function r(n) { /*...*/ }
|
|
376
|
+
// })([
|
|
377
|
+
// function (e, t) {
|
|
378
|
+
// e.exports = require("fs");
|
|
379
|
+
// },
|
|
380
|
+
// function(e, t, r) {
|
|
381
|
+
// const n = require("fs");
|
|
382
|
+
// const ns = Object.assign(a => n, { a: n });
|
|
383
|
+
// }
|
|
384
|
+
// ]);
|
|
385
|
+
//
|
|
386
|
+
// OR !(function (){})() | (function () {})() variants
|
|
387
|
+
// OR { 0: function..., 'some-id': function () ... } registry variants
|
|
388
|
+
// OR Webpack 5 non-runtime variant:
|
|
389
|
+
//
|
|
390
|
+
// (function() {
|
|
391
|
+
// var exports = {};
|
|
392
|
+
// exports.id = 223;
|
|
393
|
+
// exports.ids = [223];
|
|
394
|
+
// exports.modules = { ... };
|
|
395
|
+
// var __webpack_require__ = require("../../webpack-runtime.js");
|
|
396
|
+
// ...
|
|
397
|
+
// })()
|
|
398
|
+
//
|
|
399
|
+
else if ((wrapper.callee.type === 'FunctionExpression' &&
|
|
400
|
+
wrapper.callee.body.body.length > 2 &&
|
|
401
|
+
wrapper.callee.body.body[0].type === 'VariableDeclaration' &&
|
|
402
|
+
wrapper.callee.body.body[0].declarations.length === 1 &&
|
|
403
|
+
wrapper.callee.body.body[0].declarations[0].type ===
|
|
404
|
+
'VariableDeclarator' &&
|
|
405
|
+
wrapper.callee.body.body[0].declarations[0].id.type === 'Identifier' &&
|
|
406
|
+
wrapper.callee.body.body[0].declarations[0].init &&
|
|
407
|
+
((wrapper.callee.body.body[0].declarations[0].init.type ===
|
|
408
|
+
'ObjectExpression' &&
|
|
409
|
+
wrapper.callee.body.body[0].declarations[0].init.properties.length ===
|
|
410
|
+
0) ||
|
|
411
|
+
(wrapper.callee.body.body[0].declarations[0].init.type ===
|
|
412
|
+
'CallExpression' &&
|
|
413
|
+
wrapper.callee.body.body[0].declarations[0].init.arguments
|
|
414
|
+
.length === 1)) &&
|
|
415
|
+
((wrapper.callee.body.body[1] &&
|
|
416
|
+
wrapper.callee.body.body[1].type === 'FunctionDeclaration' &&
|
|
417
|
+
wrapper.callee.body.body[1].params.length === 1 &&
|
|
418
|
+
wrapper.callee.body.body[1].body.body.length >= 3) ||
|
|
419
|
+
(wrapper.callee.body.body[2] &&
|
|
420
|
+
wrapper.callee.body.body[2].type === 'FunctionDeclaration' &&
|
|
421
|
+
wrapper.callee.body.body[2].params.length === 1 &&
|
|
422
|
+
wrapper.callee.body.body[2].body.body.length >= 3)) &&
|
|
423
|
+
wrapper.arguments[0] &&
|
|
424
|
+
((wrapper.arguments[0].type === 'ArrayExpression' &&
|
|
425
|
+
(webpackModuleObj = wrapper.arguments[0]) &&
|
|
426
|
+
wrapper.arguments[0].elements.length > 0 &&
|
|
427
|
+
wrapper.arguments[0].elements.every((el) => el && el.type === 'FunctionExpression')) ||
|
|
428
|
+
(wrapper.arguments[0].type === 'ObjectExpression' &&
|
|
429
|
+
(webpackModuleObj = wrapper.arguments[0]) &&
|
|
430
|
+
wrapper.arguments[0].properties &&
|
|
431
|
+
wrapper.arguments[0].properties.length > 0 &&
|
|
432
|
+
wrapper.arguments[0].properties.every((prop) => prop &&
|
|
433
|
+
prop.type === 'Property' &&
|
|
434
|
+
!prop.computed &&
|
|
435
|
+
prop.key &&
|
|
436
|
+
prop.key.type === 'Literal' &&
|
|
437
|
+
(typeof prop.key.value === 'string' ||
|
|
438
|
+
typeof prop.key.value === 'number') &&
|
|
439
|
+
prop.value &&
|
|
440
|
+
prop.value.type === 'FunctionExpression')))) ||
|
|
441
|
+
(wrapper.arguments.length === 0 &&
|
|
442
|
+
wrapper.callee.type === 'FunctionExpression' &&
|
|
443
|
+
wrapper.callee.params.length === 0 &&
|
|
444
|
+
wrapper.callee.body.type === 'BlockStatement' &&
|
|
445
|
+
wrapper.callee.body.body.length > 5 &&
|
|
446
|
+
wrapper.callee.body.body[0].type === 'VariableDeclaration' &&
|
|
447
|
+
wrapper.callee.body.body[0].declarations.length === 1 &&
|
|
448
|
+
wrapper.callee.body.body[0].declarations[0].id.type === 'Identifier' &&
|
|
449
|
+
wrapper.callee.body.body[1].type === 'ExpressionStatement' &&
|
|
450
|
+
wrapper.callee.body.body[1].expression.type ===
|
|
451
|
+
'AssignmentExpression' &&
|
|
452
|
+
wrapper.callee.body.body[2].type === 'ExpressionStatement' &&
|
|
453
|
+
wrapper.callee.body.body[2].expression.type ===
|
|
454
|
+
'AssignmentExpression' &&
|
|
455
|
+
wrapper.callee.body.body[3].type === 'ExpressionStatement' &&
|
|
456
|
+
wrapper.callee.body.body[3].expression.type ===
|
|
457
|
+
'AssignmentExpression' &&
|
|
458
|
+
wrapper.callee.body.body[3].expression.left.type ===
|
|
459
|
+
'MemberExpression' &&
|
|
460
|
+
wrapper.callee.body.body[3].expression.left.object.type ===
|
|
461
|
+
'Identifier' &&
|
|
462
|
+
wrapper.callee.body.body[3].expression.left.object.name ===
|
|
463
|
+
wrapper.callee.body.body[0].declarations[0].id.name &&
|
|
464
|
+
wrapper.callee.body.body[3].expression.left.property.type ===
|
|
465
|
+
'Identifier' &&
|
|
466
|
+
wrapper.callee.body.body[3].expression.left.property.name ===
|
|
467
|
+
'modules' &&
|
|
468
|
+
wrapper.callee.body.body[3].expression.right.type ===
|
|
469
|
+
'ObjectExpression' &&
|
|
470
|
+
wrapper.callee.body.body[3].expression.right.properties.every((prop) => prop &&
|
|
471
|
+
prop.type === 'Property' &&
|
|
472
|
+
!prop.computed &&
|
|
473
|
+
prop.key &&
|
|
474
|
+
prop.key.type === 'Literal' &&
|
|
475
|
+
(typeof prop.key.value === 'string' ||
|
|
476
|
+
typeof prop.key.value === 'number') &&
|
|
477
|
+
prop.value &&
|
|
478
|
+
prop.value.type === 'FunctionExpression') &&
|
|
479
|
+
(webpackModuleObj = wrapper.callee.body.body[3].expression.right) &&
|
|
480
|
+
((wrapper.callee.body.body[4].type === 'VariableDeclaration' &&
|
|
481
|
+
wrapper.callee.body.body[4].declarations.length === 1 &&
|
|
482
|
+
wrapper.callee.body.body[4].declarations[0].init &&
|
|
483
|
+
wrapper.callee.body.body[4].declarations[0].init.type ===
|
|
484
|
+
'CallExpression' &&
|
|
485
|
+
wrapper.callee.body.body[4].declarations[0].init.callee.type ===
|
|
486
|
+
'Identifier' &&
|
|
487
|
+
wrapper.callee.body.body[4].declarations[0].init.callee.name ===
|
|
488
|
+
'require') ||
|
|
489
|
+
(wrapper.callee.body.body[5].type === 'VariableDeclaration' &&
|
|
490
|
+
wrapper.callee.body.body[5].declarations.length === 1 &&
|
|
491
|
+
wrapper.callee.body.body[5].declarations[0].init &&
|
|
492
|
+
wrapper.callee.body.body[5].declarations[0].init.type ===
|
|
493
|
+
'CallExpression' &&
|
|
494
|
+
wrapper.callee.body.body[5].declarations[0].init.callee.type ===
|
|
495
|
+
'Identifier' &&
|
|
496
|
+
wrapper.callee.body.body[5].declarations[0].init.callee.name ===
|
|
497
|
+
'require')))) {
|
|
498
|
+
const externalMap = new Map();
|
|
499
|
+
let modules;
|
|
500
|
+
if (webpackModuleObj.type === 'ArrayExpression')
|
|
501
|
+
modules = webpackModuleObj.elements.filter((el) => el?.type === 'FunctionExpression').map((el, i) => [String(i), el]);
|
|
502
|
+
// Structure already checked in conditional above
|
|
503
|
+
else
|
|
504
|
+
modules = webpackModuleObj.properties.map((prop) => [
|
|
505
|
+
String(prop.key.value),
|
|
506
|
+
prop.value,
|
|
507
|
+
]);
|
|
508
|
+
for (const [k, m] of modules) {
|
|
509
|
+
const statement = m.body.body.length === 1
|
|
510
|
+
? m.body.body[0]
|
|
511
|
+
: (m.body.body.length === 2 ||
|
|
512
|
+
(m.body.body.length === 3 &&
|
|
513
|
+
m.body.body[2].type === 'EmptyStatement')) &&
|
|
514
|
+
m.body.body[0].type === 'ExpressionStatement' &&
|
|
515
|
+
m.body.body[0].expression.type === 'Literal' &&
|
|
516
|
+
m.body.body[0].expression.value === 'use strict'
|
|
517
|
+
? m.body.body[1]
|
|
518
|
+
: null;
|
|
519
|
+
if (statement &&
|
|
520
|
+
statement.type === 'ExpressionStatement' &&
|
|
521
|
+
statement.expression.type === 'AssignmentExpression' &&
|
|
522
|
+
statement.expression.operator === '=' &&
|
|
523
|
+
statement.expression.left.type === 'MemberExpression' &&
|
|
524
|
+
statement.expression.left.object.type === 'Identifier' &&
|
|
525
|
+
'params' in m &&
|
|
526
|
+
m.params.length > 0 &&
|
|
527
|
+
'name' in m.params[0] &&
|
|
528
|
+
statement.expression.left.object.name === m.params[0].name &&
|
|
529
|
+
statement.expression.left.property.type === 'Identifier' &&
|
|
530
|
+
statement.expression.left.property.name === 'exports' &&
|
|
531
|
+
statement.expression.right.type === 'CallExpression' &&
|
|
532
|
+
statement.expression.right.callee.type === 'Identifier' &&
|
|
533
|
+
statement.expression.right.callee.name === 'require' &&
|
|
534
|
+
statement.expression.right.arguments.length === 1 &&
|
|
535
|
+
statement.expression.right.arguments[0].type === 'Literal') {
|
|
536
|
+
externalMap.set(k, statement.expression.right.arguments[0].value);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
for (const [, m] of modules) {
|
|
540
|
+
if ('params' in m &&
|
|
541
|
+
m.params.length === 3 &&
|
|
542
|
+
m.params[2].type === 'Identifier') {
|
|
543
|
+
const assignedVars = new Map();
|
|
544
|
+
(0, estree_walker_1.walk)(m.body, {
|
|
545
|
+
enter(_node, _maybeParent) {
|
|
546
|
+
const node = _node;
|
|
547
|
+
const maybeParent = _maybeParent;
|
|
548
|
+
if (node.type === 'CallExpression' &&
|
|
549
|
+
node.callee.type === 'Identifier' &&
|
|
550
|
+
'name' in m.params[2] &&
|
|
551
|
+
node.callee.name === m.params[2].name &&
|
|
552
|
+
node.arguments.length === 1 &&
|
|
553
|
+
node.arguments[0].type === 'Literal') {
|
|
554
|
+
const externalId = externalMap.get(String(node.arguments[0].value));
|
|
555
|
+
if (externalId) {
|
|
556
|
+
const replacement = {
|
|
557
|
+
type: 'CallExpression',
|
|
558
|
+
optional: false,
|
|
559
|
+
callee: {
|
|
560
|
+
type: 'Identifier',
|
|
561
|
+
name: 'require',
|
|
562
|
+
},
|
|
563
|
+
arguments: [
|
|
564
|
+
{
|
|
565
|
+
type: 'Literal',
|
|
566
|
+
value: externalId,
|
|
567
|
+
},
|
|
568
|
+
],
|
|
569
|
+
};
|
|
570
|
+
const parent = maybeParent;
|
|
571
|
+
if ('right' in parent && parent.right === node) {
|
|
572
|
+
parent.right = replacement;
|
|
573
|
+
}
|
|
574
|
+
else if ('left' in parent && parent.left === node) {
|
|
575
|
+
parent.left = replacement;
|
|
576
|
+
}
|
|
577
|
+
else if ('object' in parent && parent.object === node) {
|
|
578
|
+
parent.object = replacement;
|
|
579
|
+
}
|
|
580
|
+
else if ('callee' in parent && parent.callee === node) {
|
|
581
|
+
parent.callee = replacement;
|
|
582
|
+
}
|
|
583
|
+
else if ('arguments' in parent &&
|
|
584
|
+
parent.arguments.some((arg) => arg === node)) {
|
|
585
|
+
parent.arguments = parent.arguments.map((arg) => arg === node ? replacement : arg);
|
|
586
|
+
}
|
|
587
|
+
else if ('init' in parent && parent.init === node) {
|
|
588
|
+
if (parent.type === 'VariableDeclarator' &&
|
|
589
|
+
parent.id.type === 'Identifier')
|
|
590
|
+
assignedVars.set(parent.id.name, externalId);
|
|
591
|
+
parent.init = replacement;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
else if (node.type === 'CallExpression' &&
|
|
596
|
+
node.callee.type === 'MemberExpression' &&
|
|
597
|
+
node.callee.object.type === 'Identifier' &&
|
|
598
|
+
'name' in m.params[2] &&
|
|
599
|
+
node.callee.object.name === m.params[2].name &&
|
|
600
|
+
node.callee.property.type === 'Identifier' &&
|
|
601
|
+
node.callee.property.name === 'n' &&
|
|
602
|
+
node.arguments.length === 1 &&
|
|
603
|
+
node.arguments[0].type === 'Identifier') {
|
|
604
|
+
if (maybeParent &&
|
|
605
|
+
'init' in maybeParent &&
|
|
606
|
+
maybeParent.init === node) {
|
|
607
|
+
const req = node.arguments[0];
|
|
608
|
+
const callExpression = {
|
|
609
|
+
type: 'CallExpression',
|
|
610
|
+
optional: false,
|
|
611
|
+
callee: {
|
|
612
|
+
type: 'MemberExpression',
|
|
613
|
+
computed: false,
|
|
614
|
+
optional: false,
|
|
615
|
+
object: {
|
|
616
|
+
type: 'Identifier',
|
|
617
|
+
name: 'Object',
|
|
618
|
+
},
|
|
619
|
+
property: {
|
|
620
|
+
type: 'Identifier',
|
|
621
|
+
name: 'assign',
|
|
622
|
+
},
|
|
623
|
+
},
|
|
624
|
+
arguments: [
|
|
625
|
+
{
|
|
626
|
+
type: 'ArrowFunctionExpression',
|
|
627
|
+
expression: true,
|
|
628
|
+
params: [],
|
|
629
|
+
body: req,
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
type: 'ObjectExpression',
|
|
633
|
+
properties: [
|
|
634
|
+
{
|
|
635
|
+
type: 'Property',
|
|
636
|
+
kind: 'init',
|
|
637
|
+
method: false,
|
|
638
|
+
computed: false,
|
|
639
|
+
shorthand: false,
|
|
640
|
+
key: {
|
|
641
|
+
type: 'Identifier',
|
|
642
|
+
name: 'a',
|
|
643
|
+
},
|
|
644
|
+
value: req,
|
|
645
|
+
},
|
|
646
|
+
],
|
|
647
|
+
},
|
|
648
|
+
],
|
|
649
|
+
};
|
|
650
|
+
maybeParent.init = callExpression;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
},
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|