@atlaspack/transformer-js 3.2.3-canary.44 → 3.2.3-canary.441
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/lib/JSTransformer.js +344 -81
- package/lib/types/JSTransformer.d.ts +14 -0
- package/package.json +17 -14
- package/src/{JSTransformer.js → JSTransformer.ts} +535 -170
package/lib/JSTransformer.js
CHANGED
|
@@ -4,8 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
exports.loadCompiledCssInJsConfig = loadCompiledCssInJsConfig;
|
|
8
|
+
exports.loadTokensConfig = loadTokensConfig;
|
|
9
|
+
function _buildCache() {
|
|
10
|
+
const data = require("@atlaspack/build-cache");
|
|
11
|
+
_buildCache = function () {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
return data;
|
|
15
|
+
}
|
|
7
16
|
function _sourceMap() {
|
|
8
|
-
const data = _interopRequireDefault(require("@
|
|
17
|
+
const data = _interopRequireDefault(require("@atlaspack/source-map"));
|
|
9
18
|
_sourceMap = function () {
|
|
10
19
|
return data;
|
|
11
20
|
};
|
|
@@ -25,6 +34,13 @@ function _rust() {
|
|
|
25
34
|
};
|
|
26
35
|
return data;
|
|
27
36
|
}
|
|
37
|
+
function _assert() {
|
|
38
|
+
const data = _interopRequireDefault(require("assert"));
|
|
39
|
+
_assert = function () {
|
|
40
|
+
return data;
|
|
41
|
+
};
|
|
42
|
+
return data;
|
|
43
|
+
}
|
|
28
44
|
function _browserslist() {
|
|
29
45
|
const data = _interopRequireDefault(require("browserslist"));
|
|
30
46
|
_browserslist = function () {
|
|
@@ -68,6 +84,13 @@ function _featureFlags() {
|
|
|
68
84
|
};
|
|
69
85
|
return data;
|
|
70
86
|
}
|
|
87
|
+
function _path() {
|
|
88
|
+
const data = _interopRequireWildcard(require("path"));
|
|
89
|
+
_path = function () {
|
|
90
|
+
return data;
|
|
91
|
+
};
|
|
92
|
+
return data;
|
|
93
|
+
}
|
|
71
94
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
72
95
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
73
96
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -130,15 +153,25 @@ const CONFIG_SCHEMA = {
|
|
|
130
153
|
}
|
|
131
154
|
}]
|
|
132
155
|
},
|
|
156
|
+
addReactDisplayName: {
|
|
157
|
+
type: 'boolean'
|
|
158
|
+
},
|
|
133
159
|
magicComments: {
|
|
134
160
|
type: 'boolean'
|
|
135
161
|
},
|
|
136
162
|
unstable_inlineConstants: {
|
|
137
163
|
type: 'boolean'
|
|
164
|
+
},
|
|
165
|
+
jsx: {
|
|
166
|
+
type: 'object'
|
|
138
167
|
}
|
|
139
168
|
},
|
|
140
169
|
additionalProperties: false
|
|
141
170
|
};
|
|
171
|
+
|
|
172
|
+
// Mirrors the CONFIG_SCHEMA
|
|
173
|
+
|
|
174
|
+
const configCache = (0, _buildCache().createBuildCache)();
|
|
142
175
|
const SCRIPT_ERRORS = {
|
|
143
176
|
browser: {
|
|
144
177
|
message: 'Browser scripts cannot have imports or exports.',
|
|
@@ -155,51 +188,161 @@ const SCRIPT_ERRORS = {
|
|
|
155
188
|
};
|
|
156
189
|
|
|
157
190
|
// NOTE: Make sure this is in sync with the TypeScript definition in the @atlaspack/macros package.
|
|
191
|
+
|
|
192
|
+
const TOKENS_CONFIG_SCHEMA = {
|
|
193
|
+
type: 'object',
|
|
194
|
+
properties: {
|
|
195
|
+
shouldUseAutoFallback: {
|
|
196
|
+
type: 'boolean'
|
|
197
|
+
},
|
|
198
|
+
shouldForceAutoFallback: {
|
|
199
|
+
type: 'boolean'
|
|
200
|
+
},
|
|
201
|
+
forceAutoFallbackExemptions: {
|
|
202
|
+
type: 'array',
|
|
203
|
+
items: {
|
|
204
|
+
type: 'string'
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
defaultTheme: {
|
|
208
|
+
type: 'string',
|
|
209
|
+
enum: ['light', 'legacy-light']
|
|
210
|
+
},
|
|
211
|
+
tokenDataPath: {
|
|
212
|
+
type: 'string'
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
additionalProperties: false
|
|
216
|
+
};
|
|
217
|
+
async function legacyDetemineJsxConfig(config, options) {
|
|
218
|
+
let packageJson = await config.getPackage();
|
|
219
|
+
let isJSX, jsxPragma, jsxPragmaFrag, jsxImportSource, automaticJSXRuntime, reactRefresh;
|
|
220
|
+
if (config.isSource) {
|
|
221
|
+
var _packageJson$dependen2, _packageJson$devDepen2, _packageJson$peerDepe2, _await$config$getConf;
|
|
222
|
+
let reactLib;
|
|
223
|
+
if (packageJson !== null && packageJson !== void 0 && packageJson.alias && packageJson.alias['react']) {
|
|
224
|
+
// e.g.: `{ alias: { "react": "preact/compat" } }`
|
|
225
|
+
reactLib = 'react';
|
|
226
|
+
} else {
|
|
227
|
+
// Find a dependency that we can map to a JSX pragma
|
|
228
|
+
reactLib = Object.keys(JSX_PRAGMA).find(libName => {
|
|
229
|
+
var _packageJson$dependen, _packageJson$devDepen, _packageJson$peerDepe;
|
|
230
|
+
return (packageJson === null || packageJson === void 0 || (_packageJson$dependen = packageJson.dependencies) === null || _packageJson$dependen === void 0 ? void 0 : _packageJson$dependen[libName]) || (packageJson === null || packageJson === void 0 || (_packageJson$devDepen = packageJson.devDependencies) === null || _packageJson$devDepen === void 0 ? void 0 : _packageJson$devDepen[libName]) || (packageJson === null || packageJson === void 0 || (_packageJson$peerDepe = packageJson.peerDependencies) === null || _packageJson$peerDepe === void 0 ? void 0 : _packageJson$peerDepe[libName]);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
reactRefresh = Boolean((packageJson === null || packageJson === void 0 || (_packageJson$dependen2 = packageJson.dependencies) === null || _packageJson$dependen2 === void 0 ? void 0 : _packageJson$dependen2.react) || (packageJson === null || packageJson === void 0 || (_packageJson$devDepen2 = packageJson.devDependencies) === null || _packageJson$devDepen2 === void 0 ? void 0 : _packageJson$devDepen2.react) || (packageJson === null || packageJson === void 0 || (_packageJson$peerDepe2 = packageJson.peerDependencies) === null || _packageJson$peerDepe2 === void 0 ? void 0 : _packageJson$peerDepe2.react));
|
|
234
|
+
const compilerOptions = (_await$config$getConf = await config.getConfigFrom(options.projectRoot + '/index', ['tsconfig.json', 'jsconfig.json'], {
|
|
235
|
+
readTracking: true
|
|
236
|
+
})) === null || _await$config$getConf === void 0 || (_await$config$getConf = _await$config$getConf.contents) === null || _await$config$getConf === void 0 ? void 0 : _await$config$getConf.compilerOptions;
|
|
237
|
+
|
|
238
|
+
// Use explicitly defined JSX options in tsconfig.json over inferred values from dependencies.
|
|
239
|
+
jsxPragma = (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxFactory) || (
|
|
240
|
+
// @ts-expect-error TS7053
|
|
241
|
+
reactLib ? JSX_PRAGMA[reactLib].pragma : undefined);
|
|
242
|
+
jsxPragmaFrag = (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxFragmentFactory) || (
|
|
243
|
+
// @ts-expect-error TS7053
|
|
244
|
+
reactLib ? JSX_PRAGMA[reactLib].pragmaFrag : undefined);
|
|
245
|
+
if ((compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsx) === 'react-jsx' || (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsx) === 'react-jsxdev' || compilerOptions !== null && compilerOptions !== void 0 && compilerOptions.jsxImportSource) {
|
|
246
|
+
jsxImportSource = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxImportSource;
|
|
247
|
+
automaticJSXRuntime = true;
|
|
248
|
+
} else if (reactLib) {
|
|
249
|
+
var _JSX_PRAGMA$effective, _packageJson$dependen3, _packageJson$devDepen3, _packageJson$peerDepe3, _semver$minVersion;
|
|
250
|
+
let effectiveReactLib = packageJson !== null && packageJson !== void 0 && packageJson.alias && packageJson.alias['react'] === 'preact/compat' ? 'preact' : reactLib;
|
|
251
|
+
// @ts-expect-error TS7053
|
|
252
|
+
let automaticVersion = (_JSX_PRAGMA$effective = JSX_PRAGMA[effectiveReactLib]) === null || _JSX_PRAGMA$effective === void 0 ? void 0 : _JSX_PRAGMA$effective.automatic;
|
|
253
|
+
let reactLibVersion = (packageJson === null || packageJson === void 0 || (_packageJson$dependen3 = packageJson.dependencies) === null || _packageJson$dependen3 === void 0 ? void 0 : _packageJson$dependen3[effectiveReactLib]) || (packageJson === null || packageJson === void 0 || (_packageJson$devDepen3 = packageJson.devDependencies) === null || _packageJson$devDepen3 === void 0 ? void 0 : _packageJson$devDepen3[effectiveReactLib]) || (packageJson === null || packageJson === void 0 || (_packageJson$peerDepe3 = packageJson.peerDependencies) === null || _packageJson$peerDepe3 === void 0 ? void 0 : _packageJson$peerDepe3[effectiveReactLib]);
|
|
254
|
+
// @ts-expect-error TS2322
|
|
255
|
+
reactLibVersion = reactLibVersion ? _semver().default.validRange(reactLibVersion) : null;
|
|
256
|
+
let minReactLibVersion = reactLibVersion !== null && reactLibVersion !== '*' ? // @ts-expect-error TS2345
|
|
257
|
+
(_semver$minVersion = _semver().default.minVersion(reactLibVersion)) === null || _semver$minVersion === void 0 ? void 0 : _semver$minVersion.toString() : null;
|
|
258
|
+
automaticJSXRuntime = automaticVersion && !(compilerOptions !== null && compilerOptions !== void 0 && compilerOptions.jsxFactory) && minReactLibVersion != null && _semver().default.satisfies(minReactLibVersion, automaticVersion, {
|
|
259
|
+
includePrerelease: true
|
|
260
|
+
});
|
|
261
|
+
if (automaticJSXRuntime) {
|
|
262
|
+
jsxImportSource = reactLib;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
isJSX = Boolean((compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsx) || jsxPragma);
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
isJSX,
|
|
269
|
+
jsxPragma,
|
|
270
|
+
jsxPragmaFrag,
|
|
271
|
+
jsxImportSource,
|
|
272
|
+
automaticJSXRuntime,
|
|
273
|
+
reactRefresh
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
async function loadTokensConfig(config, options) {
|
|
277
|
+
const conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
|
|
278
|
+
packageKey: '@atlaspack/transformer-tokens'
|
|
279
|
+
});
|
|
280
|
+
if (conf && conf.contents) {
|
|
281
|
+
_utils().validateSchema.diagnostic(TOKENS_CONFIG_SCHEMA, {
|
|
282
|
+
data: conf.contents,
|
|
283
|
+
source: () => options.inputFS.readFileSync(conf.filePath, 'utf8'),
|
|
284
|
+
filePath: conf.filePath,
|
|
285
|
+
prependKey: `/${(0, _diagnostic().encodeJSONKeyComponent)('@atlaspack/transformer-tokens')}`
|
|
286
|
+
}, '@atlaspack/transformer-tokens', 'Invalid config for @atlaspack/transformer-tokens');
|
|
287
|
+
|
|
288
|
+
// @ts-expect-error TS2339
|
|
289
|
+
const tokensConfig = conf.contents;
|
|
290
|
+
let resolvedConfig = {
|
|
291
|
+
shouldUseAutoFallback: tokensConfig.shouldUseAutoFallback ?? true,
|
|
292
|
+
shouldForceAutoFallback: tokensConfig.shouldForceAutoFallback ?? true,
|
|
293
|
+
forceAutoFallbackExemptions: tokensConfig.forceAutoFallbackExemptions ?? [],
|
|
294
|
+
defaultTheme: tokensConfig.defaultTheme ?? 'light',
|
|
295
|
+
tokenDataPath: _path().default.join(options.projectRoot, tokensConfig.tokenDataPath)
|
|
296
|
+
};
|
|
297
|
+
return resolvedConfig;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
async function loadCompiledCssInJsConfig(config, options) {
|
|
301
|
+
const DEFAULT_IMPORT_SOURCES = ['@compiled/react', '@atlaskit/css'];
|
|
302
|
+
const conf = await config.getConfigFrom((0, _path().join)(options.projectRoot, 'index'), ['.compiledcssrc', '.compiledcssrc.json'], {
|
|
303
|
+
packageKey: '@atlaspack/transformer-compiled-css-in-js'
|
|
304
|
+
});
|
|
305
|
+
const contents = {
|
|
306
|
+
...(conf === null || conf === void 0 ? void 0 : conf.contents),
|
|
307
|
+
importSources: [...DEFAULT_IMPORT_SOURCES, ...((conf === null || conf === void 0 ? void 0 : conf.contents.importSources) ?? [])],
|
|
308
|
+
extract: (conf === null || conf === void 0 ? void 0 : conf.contents.extract) && options.mode !== 'development'
|
|
309
|
+
};
|
|
310
|
+
return contents;
|
|
311
|
+
}
|
|
158
312
|
var _default = exports.default = new (_plugin().Transformer)({
|
|
159
313
|
async loadConfig({
|
|
160
314
|
config,
|
|
161
315
|
options
|
|
162
316
|
}) {
|
|
163
|
-
|
|
164
|
-
let
|
|
317
|
+
var _conf$contents;
|
|
318
|
+
let conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
|
|
319
|
+
packageKey: '@atlaspack/transformer-js'
|
|
320
|
+
});
|
|
321
|
+
if (conf && conf.contents) {
|
|
322
|
+
_utils().validateSchema.diagnostic(CONFIG_SCHEMA, {
|
|
323
|
+
data: conf.contents,
|
|
324
|
+
source: () => options.inputFS.readFileSync(conf.filePath, 'utf8'),
|
|
325
|
+
filePath: conf.filePath,
|
|
326
|
+
prependKey: `/${(0, _diagnostic().encodeJSONKeyComponent)('@atlaspack/transformer-js')}`
|
|
327
|
+
},
|
|
328
|
+
// FIXME
|
|
329
|
+
'@atlaspack/transformer-js', 'Invalid config for @atlaspack/transformer-js');
|
|
330
|
+
}
|
|
331
|
+
let packageJson = await config.getPackage();
|
|
332
|
+
let decorators, useDefineForClassFields;
|
|
333
|
+
let {
|
|
334
|
+
isJSX,
|
|
335
|
+
jsxPragma,
|
|
336
|
+
jsxPragmaFrag,
|
|
337
|
+
jsxImportSource,
|
|
338
|
+
automaticJSXRuntime,
|
|
339
|
+
reactRefresh
|
|
340
|
+
} = options.featureFlags.newJsxConfig ? (0, _rust().determineJsxConfiguration)(config.searchPath, config.isSource, conf === null || conf === void 0 || (_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.jsx, options.projectRoot) : await legacyDetemineJsxConfig(config, options);
|
|
165
341
|
if (config.isSource) {
|
|
166
|
-
var
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
reactLib = 'react';
|
|
171
|
-
} else {
|
|
172
|
-
// Find a dependency that we can map to a JSX pragma
|
|
173
|
-
reactLib = Object.keys(JSX_PRAGMA).find(libName => {
|
|
174
|
-
var _pkg$dependencies, _pkg$devDependencies, _pkg$peerDependencies;
|
|
175
|
-
return (pkg === null || pkg === void 0 || (_pkg$dependencies = pkg.dependencies) === null || _pkg$dependencies === void 0 ? void 0 : _pkg$dependencies[libName]) || (pkg === null || pkg === void 0 || (_pkg$devDependencies = pkg.devDependencies) === null || _pkg$devDependencies === void 0 ? void 0 : _pkg$devDependencies[libName]) || (pkg === null || pkg === void 0 || (_pkg$peerDependencies = pkg.peerDependencies) === null || _pkg$peerDependencies === void 0 ? void 0 : _pkg$peerDependencies[libName]);
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
reactRefresh = options.hmrOptions && options.mode === 'development' && Boolean((pkg === null || pkg === void 0 || (_pkg$dependencies2 = pkg.dependencies) === null || _pkg$dependencies2 === void 0 ? void 0 : _pkg$dependencies2.react) || (pkg === null || pkg === void 0 || (_pkg$devDependencies2 = pkg.devDependencies) === null || _pkg$devDependencies2 === void 0 ? void 0 : _pkg$devDependencies2.react) || (pkg === null || pkg === void 0 || (_pkg$peerDependencies2 = pkg.peerDependencies) === null || _pkg$peerDependencies2 === void 0 ? void 0 : _pkg$peerDependencies2.react));
|
|
179
|
-
let tsconfig = await config.getConfigFrom(options.projectRoot + '/index', ['tsconfig.json', 'jsconfig.json']);
|
|
180
|
-
let compilerOptions = tsconfig === null || tsconfig === void 0 || (_tsconfig$contents = tsconfig.contents) === null || _tsconfig$contents === void 0 ? void 0 : _tsconfig$contents.compilerOptions;
|
|
181
|
-
|
|
182
|
-
// Use explicitly defined JSX options in tsconfig.json over inferred values from dependencies.
|
|
183
|
-
pragma = (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxFactory) || (reactLib ? JSX_PRAGMA[reactLib].pragma : undefined);
|
|
184
|
-
pragmaFrag = (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxFragmentFactory) || (reactLib ? JSX_PRAGMA[reactLib].pragmaFrag : undefined);
|
|
185
|
-
if ((compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsx) === 'react-jsx' || (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsx) === 'react-jsxdev' || compilerOptions !== null && compilerOptions !== void 0 && compilerOptions.jsxImportSource) {
|
|
186
|
-
jsxImportSource = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxImportSource;
|
|
187
|
-
automaticJSXRuntime = true;
|
|
188
|
-
} else if (reactLib) {
|
|
189
|
-
var _JSX_PRAGMA$effective, _pkg$dependencies3, _pkg$devDependencies3, _pkg$peerDependencies3, _semver$minVersion;
|
|
190
|
-
let effectiveReactLib = pkg !== null && pkg !== void 0 && pkg.alias && pkg.alias['react'] === 'preact/compat' ? 'preact' : reactLib;
|
|
191
|
-
let automaticVersion = (_JSX_PRAGMA$effective = JSX_PRAGMA[effectiveReactLib]) === null || _JSX_PRAGMA$effective === void 0 ? void 0 : _JSX_PRAGMA$effective.automatic;
|
|
192
|
-
let reactLibVersion = (pkg === null || pkg === void 0 || (_pkg$dependencies3 = pkg.dependencies) === null || _pkg$dependencies3 === void 0 ? void 0 : _pkg$dependencies3[effectiveReactLib]) || (pkg === null || pkg === void 0 || (_pkg$devDependencies3 = pkg.devDependencies) === null || _pkg$devDependencies3 === void 0 ? void 0 : _pkg$devDependencies3[effectiveReactLib]) || (pkg === null || pkg === void 0 || (_pkg$peerDependencies3 = pkg.peerDependencies) === null || _pkg$peerDependencies3 === void 0 ? void 0 : _pkg$peerDependencies3[effectiveReactLib]);
|
|
193
|
-
reactLibVersion = reactLibVersion ? _semver().default.validRange(reactLibVersion) : null;
|
|
194
|
-
let minReactLibVersion = reactLibVersion !== null && reactLibVersion !== '*' ? (_semver$minVersion = _semver().default.minVersion(reactLibVersion)) === null || _semver$minVersion === void 0 ? void 0 : _semver$minVersion.toString() : null;
|
|
195
|
-
automaticJSXRuntime = automaticVersion && !(compilerOptions !== null && compilerOptions !== void 0 && compilerOptions.jsxFactory) && minReactLibVersion != null && _semver().default.satisfies(minReactLibVersion, automaticVersion, {
|
|
196
|
-
includePrerelease: true
|
|
197
|
-
});
|
|
198
|
-
if (automaticJSXRuntime) {
|
|
199
|
-
jsxImportSource = reactLib;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
isJSX = Boolean((compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsx) || pragma);
|
|
342
|
+
var _await$config$getConf2;
|
|
343
|
+
const compilerOptions = (_await$config$getConf2 = await config.getConfigFrom(options.projectRoot + '/index', ['tsconfig.json', 'jsconfig.json'], {
|
|
344
|
+
readTracking: true
|
|
345
|
+
})) === null || _await$config$getConf2 === void 0 || (_await$config$getConf2 = _await$config$getConf2.contents) === null || _await$config$getConf2 === void 0 ? void 0 : _await$config$getConf2.compilerOptions;
|
|
203
346
|
decorators = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.experimentalDecorators;
|
|
204
347
|
useDefineForClassFields = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.useDefineForClassFields;
|
|
205
348
|
if (useDefineForClassFields === undefined && (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.target) != null) {
|
|
@@ -215,43 +358,88 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
215
358
|
|
|
216
359
|
// Check if we should ignore fs calls
|
|
217
360
|
// See https://github.com/defunctzombie/node-browser-resolve#skip
|
|
218
|
-
let ignoreFS =
|
|
219
|
-
let conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
|
|
220
|
-
packageKey: '@atlaspack/transformer-js'
|
|
221
|
-
});
|
|
361
|
+
let ignoreFS = packageJson && packageJson.browser && typeof packageJson.browser === 'object' && packageJson.browser.fs === false;
|
|
222
362
|
let inlineEnvironment = config.isSource;
|
|
223
363
|
let inlineFS = !ignoreFS;
|
|
224
364
|
let inlineConstants = false;
|
|
225
365
|
let magicComments = false;
|
|
366
|
+
let addReactDisplayName = false;
|
|
367
|
+
let enableSsrTypeofReplacement = options.env.NATIVE_SSR_TYPEOF_REPLACEMENT === 'true';
|
|
368
|
+
let globalAliasingConfig = options.env.NATIVE_GLOBAL_ALIASING && JSON.parse(options.env.NATIVE_GLOBAL_ALIASING);
|
|
369
|
+
let enableLazyLoading = options.env.NATIVE_LAZY_LOADING === 'true';
|
|
370
|
+
let enableReactHooksRemoval = options.env.NATIVE_REACT_HOOKS_REMOVAL === 'true';
|
|
371
|
+
let enableReactAsyncImportLift = options.env.NATIVE_REACT_ASYNC_IMPORT_LIFT === 'true';
|
|
372
|
+
let reactAsyncLiftByDefault = options.env.REACT_ASYNC_IMPORT_LIFTING_BY_DEFAULT === 'true';
|
|
373
|
+
let reactAsyncLiftReportLevel = options.env.REACT_ASYNC_LIFT_REPORT_LEVEL || 'none';
|
|
374
|
+
let enableStaticPrevaluation = options.env.NATIVE_PREVALUATION === 'true';
|
|
375
|
+
let enableDeadReturnsRemoval = options.env.NATIVE_DEAD_RETURNS_REMOVAL === 'true';
|
|
376
|
+
let enableUnusedBindingsRemoval = options.env.NATIVE_UNUSED_BINDINGS_REMOVAL === 'true';
|
|
377
|
+
let syncDynamicImportConfig;
|
|
378
|
+
if (config.env.isTesseract() && options.env.SYNC_DYNAMIC_IMPORT_CONFIG) {
|
|
379
|
+
try {
|
|
380
|
+
let config = configCache.get('SYNC_DYNAMIC_IMPORT_CONFIG');
|
|
381
|
+
if (!config) {
|
|
382
|
+
var _config;
|
|
383
|
+
config = JSON.parse(options.env.SYNC_DYNAMIC_IMPORT_CONFIG);
|
|
384
|
+
(0, _assert().default)(typeof ((_config = config) === null || _config === void 0 ? void 0 : _config.entrypoint_filepath_suffix) === 'string');
|
|
385
|
+
(0, _assert().default)(Array.isArray(config.actual_require_paths));
|
|
386
|
+
(0, _assert().default)(typeof (config.activate_reject_on_unresolved_imports ?? false) === 'boolean');
|
|
387
|
+
configCache.set('SYNC_DYNAMIC_IMPORT_CONFIG', config);
|
|
388
|
+
}
|
|
389
|
+
syncDynamicImportConfig = config;
|
|
390
|
+
} catch {
|
|
391
|
+
// eslint-disable-next-line no-console
|
|
392
|
+
console.warn('Failed to parse SYNC_DYNAMIC_IMPORT_CONFIG to JSON or config shape did not match. Config will not be applied.');
|
|
393
|
+
const fallback = {
|
|
394
|
+
entrypoint_filepath_suffix: '__NO_MATCH__',
|
|
395
|
+
actual_require_paths: [],
|
|
396
|
+
activate_reject_on_unresolved_imports: false
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
// Set cache to fallback so we don't keep trying to parse.
|
|
400
|
+
configCache.set('SYNC_DYNAMIC_IMPORT_CONFIG', fallback);
|
|
401
|
+
syncDynamicImportConfig = fallback;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
config.invalidateOnEnvChange('SYNC_DYNAMIC_IMPORT_CONFIG');
|
|
405
|
+
const tokensConfig = (0, _featureFlags().getFeatureFlag)('coreTokensAndCompiledCssInJsTransform') ? await loadTokensConfig(config, options) : undefined;
|
|
406
|
+
const compiledCssInJsConfig = (0, _featureFlags().getFeatureFlag)('coreTokensAndCompiledCssInJsTransform') ? await loadCompiledCssInJsConfig(config, options) : undefined;
|
|
226
407
|
if (conf && conf.contents) {
|
|
227
|
-
var _conf$
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
},
|
|
235
|
-
// FIXME
|
|
236
|
-
'@atlaspack/transformer-js', 'Invalid config for @atlaspack/transformer-js');
|
|
237
|
-
magicComments = ((_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.magicComments) ?? magicComments;
|
|
238
|
-
inlineEnvironment = ((_conf$contents2 = conf.contents) === null || _conf$contents2 === void 0 ? void 0 : _conf$contents2.inlineEnvironment) ?? inlineEnvironment;
|
|
239
|
-
inlineFS = ((_conf$contents3 = conf.contents) === null || _conf$contents3 === void 0 ? void 0 : _conf$contents3.inlineFS) ?? inlineFS;
|
|
240
|
-
inlineConstants = ((_conf$contents4 = conf.contents) === null || _conf$contents4 === void 0 ? void 0 : _conf$contents4.unstable_inlineConstants) ?? inlineConstants;
|
|
408
|
+
var _conf$contents2, _conf$contents3, _conf$contents4, _conf$contents5, _conf$contents6;
|
|
409
|
+
addReactDisplayName = ((_conf$contents2 = conf.contents) === null || _conf$contents2 === void 0 ? void 0 : _conf$contents2.addReactDisplayName) ?? addReactDisplayName;
|
|
410
|
+
magicComments = ((_conf$contents3 = conf.contents) === null || _conf$contents3 === void 0 ? void 0 : _conf$contents3.magicComments) ?? magicComments;
|
|
411
|
+
// @ts-expect-error TS2322
|
|
412
|
+
inlineEnvironment = ((_conf$contents4 = conf.contents) === null || _conf$contents4 === void 0 ? void 0 : _conf$contents4.inlineEnvironment) ?? inlineEnvironment;
|
|
413
|
+
inlineFS = ((_conf$contents5 = conf.contents) === null || _conf$contents5 === void 0 ? void 0 : _conf$contents5.inlineFS) ?? inlineFS;
|
|
414
|
+
inlineConstants = ((_conf$contents6 = conf.contents) === null || _conf$contents6 === void 0 ? void 0 : _conf$contents6.unstable_inlineConstants) ?? inlineConstants;
|
|
241
415
|
}
|
|
242
416
|
return {
|
|
243
417
|
isJSX,
|
|
244
418
|
automaticJSXRuntime,
|
|
245
419
|
jsxImportSource,
|
|
246
|
-
pragma,
|
|
247
|
-
pragmaFrag,
|
|
420
|
+
pragma: jsxPragma,
|
|
421
|
+
pragmaFrag: jsxPragmaFrag,
|
|
248
422
|
inlineEnvironment,
|
|
249
423
|
inlineFS,
|
|
250
424
|
inlineConstants,
|
|
425
|
+
addReactDisplayName,
|
|
251
426
|
reactRefresh,
|
|
252
427
|
decorators,
|
|
253
428
|
useDefineForClassFields,
|
|
254
|
-
magicComments
|
|
429
|
+
magicComments,
|
|
430
|
+
globalAliasingConfig,
|
|
431
|
+
enableSsrTypeofReplacement,
|
|
432
|
+
enableLazyLoading,
|
|
433
|
+
enableDeadReturnsRemoval,
|
|
434
|
+
enableUnusedBindingsRemoval,
|
|
435
|
+
enableStaticPrevaluation,
|
|
436
|
+
enableReactHooksRemoval,
|
|
437
|
+
syncDynamicImportConfig,
|
|
438
|
+
enableReactAsyncImportLift,
|
|
439
|
+
reactAsyncLiftByDefault,
|
|
440
|
+
reactAsyncLiftReportLevel,
|
|
441
|
+
tokensConfig,
|
|
442
|
+
compiledCssInJsConfig
|
|
255
443
|
};
|
|
256
444
|
},
|
|
257
445
|
async transform({
|
|
@@ -280,17 +468,22 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
280
468
|
for (let browser of browsers) {
|
|
281
469
|
let [name, version] = browser.split(' ');
|
|
282
470
|
if (BROWSER_MAPPING.hasOwnProperty(name)) {
|
|
471
|
+
// @ts-expect-error TS7053
|
|
283
472
|
name = BROWSER_MAPPING[name];
|
|
284
473
|
if (!name) {
|
|
285
474
|
continue;
|
|
286
475
|
}
|
|
287
476
|
}
|
|
288
477
|
let [major, minor = '0', patch = '0'] = version.split('-')[0].split('.');
|
|
478
|
+
// @ts-expect-error TS2345
|
|
289
479
|
if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
|
|
290
480
|
continue;
|
|
291
481
|
}
|
|
292
482
|
let semverVersion = `${major}.${minor}.${patch}`;
|
|
483
|
+
|
|
484
|
+
// @ts-expect-error TS2345
|
|
293
485
|
if (targets[name] == null || _semver().default.gt(targets[name], semverVersion)) {
|
|
486
|
+
// @ts-expect-error TS7053
|
|
294
487
|
targets[name] = semverVersion;
|
|
295
488
|
}
|
|
296
489
|
}
|
|
@@ -305,6 +498,9 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
305
498
|
if (options.env.NODE_ENV != null) {
|
|
306
499
|
env.NODE_ENV = options.env.NODE_ENV;
|
|
307
500
|
}
|
|
501
|
+
if (process.env.ATLASPACK_BUILD_ENV === 'test') {
|
|
502
|
+
env.ATLASPACK_BUILD_ENV = 'test';
|
|
503
|
+
}
|
|
308
504
|
} else if (Array.isArray(config === null || config === void 0 ? void 0 : config.inlineEnvironment)) {
|
|
309
505
|
for (let match of (0, _utils().globMatch)(Object.keys(options.env), config.inlineEnvironment)) {
|
|
310
506
|
env[match] = String(options.env[match]);
|
|
@@ -322,23 +518,42 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
322
518
|
if (asset.type === 'ts') {
|
|
323
519
|
isJSX = false;
|
|
324
520
|
} else if (!isJSX) {
|
|
521
|
+
// @ts-expect-error TS7053
|
|
325
522
|
isJSX = Boolean(JSX_EXTENSIONS[asset.type]);
|
|
326
523
|
}
|
|
327
524
|
}
|
|
328
525
|
let macroAssets = [];
|
|
329
526
|
let {
|
|
527
|
+
// @ts-expect-error TS2339
|
|
330
528
|
dependencies,
|
|
529
|
+
// @ts-expect-error TS2339
|
|
331
530
|
code: compiledCode,
|
|
531
|
+
// @ts-expect-error TS2339
|
|
332
532
|
map,
|
|
533
|
+
// @ts-expect-error TS2339
|
|
333
534
|
shebang,
|
|
535
|
+
// @ts-expect-error TS2339
|
|
334
536
|
hoist_result,
|
|
537
|
+
// @ts-expect-error TS2339
|
|
335
538
|
symbol_result,
|
|
539
|
+
// @ts-expect-error TS2339
|
|
540
|
+
is_empty_or_empty_export,
|
|
541
|
+
// @ts-expect-error TS2339
|
|
336
542
|
needs_esm_helpers,
|
|
543
|
+
// @ts-expect-error TS2339
|
|
337
544
|
diagnostics,
|
|
545
|
+
// @ts-expect-error TS2339
|
|
338
546
|
used_env,
|
|
547
|
+
// @ts-expect-error TS2339
|
|
339
548
|
has_node_replacements,
|
|
549
|
+
// @ts-expect-error TS2339
|
|
340
550
|
is_constant_module,
|
|
341
|
-
|
|
551
|
+
// @ts-expect-error TS2339
|
|
552
|
+
conditions,
|
|
553
|
+
// @ts-expect-error TS2339
|
|
554
|
+
magic_comments,
|
|
555
|
+
// @ts-expect-error TS2339
|
|
556
|
+
style_rules
|
|
342
557
|
} = await (_rust().transformAsync || _rust().transform)({
|
|
343
558
|
filename: asset.filePath,
|
|
344
559
|
code,
|
|
@@ -349,7 +564,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
349
564
|
insert_node_globals: !asset.env.isNode() && asset.env.sourceType !== 'script',
|
|
350
565
|
node_replacer: asset.env.isNode(),
|
|
351
566
|
is_browser: asset.env.isBrowser(),
|
|
352
|
-
is_worker: asset.env.isWorker(),
|
|
567
|
+
is_worker: asset.env.isWorker() || asset.env.isTesseract(),
|
|
353
568
|
env,
|
|
354
569
|
is_type_script: asset.type === 'ts' || asset.type === 'tsx',
|
|
355
570
|
is_jsx: isJSX,
|
|
@@ -358,7 +573,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
358
573
|
automatic_jsx_runtime: Boolean(config === null || config === void 0 ? void 0 : config.automaticJSXRuntime),
|
|
359
574
|
jsx_import_source: config === null || config === void 0 ? void 0 : config.jsxImportSource,
|
|
360
575
|
is_development: options.mode === 'development',
|
|
361
|
-
react_refresh: asset.env.isBrowser() && !asset.env.isLibrary && !asset.env.isWorker() && !asset.env.isWorklet() &&
|
|
576
|
+
react_refresh: Boolean(asset.env.isBrowser() && !asset.env.isLibrary && !asset.env.isWorker() && !asset.env.isTesseract() && !asset.env.isWorklet() && (config === null || config === void 0 ? void 0 : config.reactRefresh) && options.hmrOptions && options.mode === 'development'),
|
|
362
577
|
decorators: Boolean(config === null || config === void 0 ? void 0 : config.decorators),
|
|
363
578
|
use_define_for_class_fields: Boolean(config === null || config === void 0 ? void 0 : config.useDefineForClassFields),
|
|
364
579
|
targets,
|
|
@@ -373,16 +588,33 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
373
588
|
standalone: asset.query.has('standalone'),
|
|
374
589
|
inline_constants: config.inlineConstants,
|
|
375
590
|
conditional_bundling: options.featureFlags.conditionalBundlingApi,
|
|
376
|
-
|
|
591
|
+
hmr_improvements: options.featureFlags.hmrImprovements,
|
|
592
|
+
add_display_name: Boolean(config.addReactDisplayName),
|
|
593
|
+
exports_rebinding_optimisation: options.featureFlags.exportsRebindingOptimisation,
|
|
594
|
+
magic_comments: Boolean(config === null || config === void 0 ? void 0 : config.magicComments) || (0, _featureFlags().getFeatureFlag)('supportWebpackChunkName'),
|
|
595
|
+
is_source: asset.isSource,
|
|
596
|
+
nested_promise_import_fix: options.featureFlags.nestedPromiseImportFix,
|
|
597
|
+
global_aliasing_config: config.globalAliasingConfig,
|
|
598
|
+
enable_ssr_typeof_replacement: Boolean(config.enableSsrTypeofReplacement),
|
|
599
|
+
enable_lazy_loading: Boolean(config.enableLazyLoading),
|
|
600
|
+
enable_dead_returns_removal: Boolean(config.enableDeadReturnsRemoval),
|
|
601
|
+
enable_unused_bindings_removal: Boolean(config.enableUnusedBindingsRemoval),
|
|
602
|
+
enable_static_prevaluation: Boolean(config.enableStaticPrevaluation),
|
|
603
|
+
enable_react_hooks_removal: Boolean(config.enableReactHooksRemoval),
|
|
604
|
+
enable_react_async_import_lift: Boolean(config.enableReactAsyncImportLift),
|
|
605
|
+
react_async_lift_by_default: Boolean(config.reactAsyncLiftByDefault),
|
|
606
|
+
react_async_lift_report_level: String(config.reactAsyncLiftReportLevel),
|
|
607
|
+
sync_dynamic_import_config: config.syncDynamicImportConfig,
|
|
608
|
+
enable_tokens_and_compiled_css_in_js_transform: (0, _featureFlags().getFeatureFlag)('coreTokensAndCompiledCssInJsTransform'),
|
|
609
|
+
tokens_config: config.tokensConfig,
|
|
610
|
+
compiled_css_in_js_config: config.compiledCssInJsConfig,
|
|
377
611
|
callMacro: asset.isSource ? async (err, src, exportName, args, loc) => {
|
|
378
612
|
let mod;
|
|
379
613
|
try {
|
|
380
614
|
mod = await options.packageManager.require(src, asset.filePath);
|
|
381
615
|
|
|
382
616
|
// Default interop for CommonJS modules.
|
|
383
|
-
if (exportName === 'default' && !mod.__esModule &&
|
|
384
|
-
// $FlowFixMe
|
|
385
|
-
Object.prototype.toString.call(config) !== '[object Module]') {
|
|
617
|
+
if (exportName === 'default' && !mod.__esModule && Object.prototype.toString.call(config) !== '[object Module]') {
|
|
386
618
|
mod = {
|
|
387
619
|
default: mod
|
|
388
620
|
};
|
|
@@ -398,7 +630,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
398
630
|
}
|
|
399
631
|
try {
|
|
400
632
|
if (typeof mod[exportName] === 'function') {
|
|
401
|
-
|
|
633
|
+
let ctx = {
|
|
402
634
|
// Allows macros to emit additional assets to add as dependencies (e.g. css).
|
|
403
635
|
addAsset(a) {
|
|
404
636
|
let k = String(macroAssets.length);
|
|
@@ -406,6 +638,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
406
638
|
if (asset.env.sourceMap) {
|
|
407
639
|
// Generate a source map that maps each line of the asset to the original macro call.
|
|
408
640
|
map = new (_sourceMap().default)(options.projectRoot);
|
|
641
|
+
// @ts-expect-error TS2304
|
|
409
642
|
let mappings = [];
|
|
410
643
|
let line = 1;
|
|
411
644
|
for (let i = 0; i <= a.content.length; i++) {
|
|
@@ -428,7 +661,9 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
428
661
|
if (originalMap) {
|
|
429
662
|
map.extends(originalMap);
|
|
430
663
|
} else {
|
|
431
|
-
|
|
664
|
+
if (!(0, _featureFlags().getFeatureFlag)('omitSourcesContentInMemory')) {
|
|
665
|
+
map.setSourceContent(asset.filePath, code.toString());
|
|
666
|
+
}
|
|
432
667
|
}
|
|
433
668
|
}
|
|
434
669
|
macroAssets.push({
|
|
@@ -457,7 +692,8 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
457
692
|
invalidateOnBuild() {
|
|
458
693
|
asset.invalidateOnBuild();
|
|
459
694
|
}
|
|
460
|
-
}
|
|
695
|
+
};
|
|
696
|
+
return mod[exportName].apply(ctx, args);
|
|
461
697
|
} else {
|
|
462
698
|
throw new Error(`"${exportName}" in "${src}" is not a function.`);
|
|
463
699
|
}
|
|
@@ -479,11 +715,10 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
479
715
|
} : null
|
|
480
716
|
});
|
|
481
717
|
if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi')) {
|
|
482
|
-
asset.meta.conditions = conditions
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
}));
|
|
718
|
+
asset.meta.conditions = conditions;
|
|
719
|
+
}
|
|
720
|
+
if (style_rules) {
|
|
721
|
+
asset.meta.styleRules = style_rules;
|
|
487
722
|
}
|
|
488
723
|
if (is_constant_module) {
|
|
489
724
|
asset.meta.isConstantModule = true;
|
|
@@ -503,17 +738,22 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
503
738
|
|
|
504
739
|
// If there is an original source map, use it to remap to the original source location.
|
|
505
740
|
if (originalMap) {
|
|
506
|
-
location = (0, _utils().remapSourceLocation)(location, originalMap);
|
|
741
|
+
location = (0, _utils().remapSourceLocation)(location, originalMap, options.projectRoot);
|
|
507
742
|
}
|
|
508
743
|
return location;
|
|
509
744
|
};
|
|
510
745
|
if (diagnostics) {
|
|
511
|
-
let errors = diagnostics.filter(
|
|
512
|
-
|
|
746
|
+
let errors = diagnostics.filter(
|
|
747
|
+
// @ts-expect-error TS7006
|
|
748
|
+
d => d.severity === 'Error' || d.severity === 'SourceError' && asset.isSource);
|
|
749
|
+
let warnings = diagnostics.filter(
|
|
750
|
+
// @ts-expect-error TS7006
|
|
751
|
+
d => d.severity === 'Warning' || d.severity === 'SourceError' && !asset.isSource);
|
|
513
752
|
let convertDiagnostic = diagnostic => {
|
|
514
753
|
var _diagnostic$code_high;
|
|
515
754
|
let message = diagnostic.message;
|
|
516
755
|
if (message === 'SCRIPT_ERROR') {
|
|
756
|
+
// @ts-expect-error TS7053
|
|
517
757
|
let err = SCRIPT_ERRORS[asset.env.context];
|
|
518
758
|
message = (err === null || err === void 0 ? void 0 : err.message) || SCRIPT_ERRORS.browser.message;
|
|
519
759
|
}
|
|
@@ -536,6 +776,8 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
536
776
|
codeHighlights: [(0, _diagnostic().convertSourceLocationToHighlight)(asset.env.loc, 'The environment was originally created here')]
|
|
537
777
|
});
|
|
538
778
|
}
|
|
779
|
+
|
|
780
|
+
// @ts-expect-error TS7053
|
|
539
781
|
let err = SCRIPT_ERRORS[asset.env.context];
|
|
540
782
|
if (err) {
|
|
541
783
|
if (!res.hints) {
|
|
@@ -580,6 +822,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
580
822
|
env: {
|
|
581
823
|
context: 'web-worker',
|
|
582
824
|
sourceType: dep.source_type === 'Module' ? 'module' : 'script',
|
|
825
|
+
// @ts-expect-error TS2322
|
|
583
826
|
outputFormat,
|
|
584
827
|
loc
|
|
585
828
|
},
|
|
@@ -629,6 +872,13 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
629
872
|
});
|
|
630
873
|
} else if (dep.kind === 'File') {
|
|
631
874
|
asset.invalidateOnFileChange(dep.specifier);
|
|
875
|
+
} else if (dep.kind === 'Id') {
|
|
876
|
+
// Record parcelRequire calls so that the dev packager can add them as dependencies.
|
|
877
|
+
// This allows the HMR runtime to collect parents across async boundaries (through runtimes).
|
|
878
|
+
// TODO: ideally this would result as an actual dep in the graph rather than asset.meta.
|
|
879
|
+
asset.meta.hmrDeps ??= [];
|
|
880
|
+
(0, _assert().default)(Array.isArray(asset.meta.hmrDeps));
|
|
881
|
+
asset.meta.hmrDeps.push(dep.specifier);
|
|
632
882
|
} else {
|
|
633
883
|
let meta = {
|
|
634
884
|
kind: dep.kind
|
|
@@ -676,6 +926,12 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
676
926
|
outputFormat,
|
|
677
927
|
loc: convertLoc(dep.loc)
|
|
678
928
|
};
|
|
929
|
+
if ((0, _featureFlags().getFeatureFlag)('supportWebpackChunkName')) {
|
|
930
|
+
let chunkName = magic_comments[dep.specifier];
|
|
931
|
+
if (chunkName) {
|
|
932
|
+
meta.chunkName = chunkName;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
679
935
|
}
|
|
680
936
|
|
|
681
937
|
// Always bundle helpers, even with includeNodeModules: false, except if this is a library.
|
|
@@ -695,6 +951,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
695
951
|
idx = dep.specifier.indexOf('/', idx + 1);
|
|
696
952
|
}
|
|
697
953
|
let module = idx >= 0 ? dep.specifier.slice(0, idx) : dep.specifier;
|
|
954
|
+
// @ts-expect-error TS7053
|
|
698
955
|
range = _package.default.dependencies[module];
|
|
699
956
|
}
|
|
700
957
|
asset.addDependency({
|
|
@@ -706,6 +963,7 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
706
963
|
meta,
|
|
707
964
|
resolveFrom: isHelper ? __filename : undefined,
|
|
708
965
|
range,
|
|
966
|
+
// @ts-expect-error TS2322
|
|
709
967
|
env
|
|
710
968
|
});
|
|
711
969
|
}
|
|
@@ -717,10 +975,12 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
717
975
|
exported,
|
|
718
976
|
local,
|
|
719
977
|
loc,
|
|
720
|
-
is_esm
|
|
978
|
+
is_esm,
|
|
979
|
+
is_static_binding_safe
|
|
721
980
|
} of hoist_result.exported_symbols) {
|
|
722
981
|
asset.symbols.set(exported, local, convertLoc(loc), {
|
|
723
|
-
isEsm: is_esm
|
|
982
|
+
isEsm: is_esm,
|
|
983
|
+
isStaticBindingSafe: is_static_binding_safe
|
|
724
984
|
});
|
|
725
985
|
}
|
|
726
986
|
|
|
@@ -802,6 +1062,9 @@ var _default = exports.default = new (_plugin().Transformer)({
|
|
|
802
1062
|
// (and the asset has side effects), or the asset is wrapped.
|
|
803
1063
|
// This allows accessing symbols that don't exist without errors in symbol propagation.
|
|
804
1064
|
if (hoist_result.has_cjs_exports || !hoist_result.is_esm && asset.sideEffects && deps.size === 0 && Object.keys(hoist_result.exported_symbols).length === 0 || hoist_result.should_wrap && !asset.symbols.hasExportSymbol('*')) {
|
|
1065
|
+
if (is_empty_or_empty_export) {
|
|
1066
|
+
asset.meta.emptyFileStarReexport = true;
|
|
1067
|
+
}
|
|
805
1068
|
asset.symbols.set('*', `$${asset.id}$exports`);
|
|
806
1069
|
}
|
|
807
1070
|
asset.meta.hasCJSExports = hoist_result.has_cjs_exports;
|