@atlaspack/packager-js 2.12.1-dev.3367 → 2.12.1-dev.3398
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/DevPackager.js +7 -7
- package/lib/ESMOutputFormat.js +2 -2
- package/lib/ScopeHoistingPackager.js +55 -55
- package/lib/dev-prelude.js +8 -8
- package/lib/helpers.js +39 -39
- package/lib/index.js +4 -4
- package/lib/utils.js +5 -5
- package/package.json +8 -8
- package/src/DevPackager.js +8 -8
- package/src/ESMOutputFormat.js +2 -2
- package/src/ScopeHoistingPackager.js +56 -56
- package/src/dev-prelude.js +8 -8
- package/src/helpers.js +46 -48
- package/src/index.js +6 -6
- package/src/utils.js +25 -28
package/src/helpers.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
// @flow strict-local
|
|
2
2
|
import type {Environment} from '@atlaspack/types';
|
|
3
3
|
|
|
4
|
-
export const prelude = (
|
|
5
|
-
var $
|
|
6
|
-
var $
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
if (id in $atlaspack$modules) {
|
|
15
|
-
return $atlaspack$modules[id].exports;
|
|
4
|
+
export const prelude = (parcelRequireName: string): string => `
|
|
5
|
+
var $parcel$modules = {};
|
|
6
|
+
var $parcel$inits = {};
|
|
7
|
+
|
|
8
|
+
var parcelRequire = $parcel$global[${JSON.stringify(parcelRequireName)}];
|
|
9
|
+
|
|
10
|
+
if (parcelRequire == null) {
|
|
11
|
+
parcelRequire = function(id) {
|
|
12
|
+
if (id in $parcel$modules) {
|
|
13
|
+
return $parcel$modules[id].exports;
|
|
16
14
|
}
|
|
17
|
-
if (id in $
|
|
18
|
-
var init = $
|
|
19
|
-
delete $
|
|
15
|
+
if (id in $parcel$inits) {
|
|
16
|
+
var init = $parcel$inits[id];
|
|
17
|
+
delete $parcel$inits[id];
|
|
20
18
|
var module = {id: id, exports: {}};
|
|
21
|
-
$
|
|
19
|
+
$parcel$modules[id] = module;
|
|
22
20
|
init.call(module.exports, module, module.exports);
|
|
23
21
|
return module.exports;
|
|
24
22
|
}
|
|
@@ -27,14 +25,14 @@ if (atlaspackRequire == null) {
|
|
|
27
25
|
throw err;
|
|
28
26
|
};
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
$
|
|
28
|
+
parcelRequire.register = function register(id, init) {
|
|
29
|
+
$parcel$inits[id] = init;
|
|
32
30
|
};
|
|
33
31
|
|
|
34
|
-
$
|
|
32
|
+
$parcel$global[${JSON.stringify(parcelRequireName)}] = parcelRequire;
|
|
35
33
|
}
|
|
36
34
|
|
|
37
|
-
var
|
|
35
|
+
var parcelRegister = parcelRequire.register;
|
|
38
36
|
`;
|
|
39
37
|
|
|
40
38
|
export const fnExpr = (
|
|
@@ -52,67 +50,67 @@ export const fnExpr = (
|
|
|
52
50
|
};
|
|
53
51
|
|
|
54
52
|
export const bundleQueuePrelude = (env: Environment): string => `
|
|
55
|
-
if (!$
|
|
53
|
+
if (!$parcel$global.lb) {
|
|
56
54
|
// Set of loaded bundles
|
|
57
|
-
$
|
|
55
|
+
$parcel$global.lb = new Set();
|
|
58
56
|
// Queue of bundles to execute once they're dep bundles are loaded
|
|
59
|
-
$
|
|
57
|
+
$parcel$global.bq = [];
|
|
60
58
|
|
|
61
59
|
// Register loaded bundle
|
|
62
|
-
$
|
|
60
|
+
$parcel$global.rlb = ${fnExpr(
|
|
63
61
|
env,
|
|
64
62
|
['bundle'],
|
|
65
|
-
['$
|
|
63
|
+
['$parcel$global.lb.add(bundle);', '$parcel$global.pq();'],
|
|
66
64
|
)}
|
|
67
65
|
|
|
68
66
|
// Run when ready
|
|
69
|
-
$
|
|
67
|
+
$parcel$global.rwr = ${fnExpr(
|
|
70
68
|
env,
|
|
71
69
|
// b = bundle public id
|
|
72
70
|
// r = run function to execute the bundle entry
|
|
73
71
|
// d = list of dependent bundles this bundle requires before executing
|
|
74
72
|
['b', 'r', 'd'],
|
|
75
|
-
['$
|
|
73
|
+
['$parcel$global.bq.push({b, r, d});', '$parcel$global.pq();'],
|
|
76
74
|
)}
|
|
77
75
|
|
|
78
76
|
// Process queue
|
|
79
|
-
$
|
|
77
|
+
$parcel$global.pq = ${fnExpr(
|
|
80
78
|
env,
|
|
81
79
|
[],
|
|
82
80
|
[
|
|
83
|
-
`var runnableEntry = $
|
|
81
|
+
`var runnableEntry = $parcel$global.bq.find(${fnExpr(
|
|
84
82
|
env,
|
|
85
83
|
['i'],
|
|
86
84
|
[
|
|
87
85
|
`return i.d.every(${fnExpr(
|
|
88
86
|
env,
|
|
89
87
|
['dep'],
|
|
90
|
-
['return $
|
|
88
|
+
['return $parcel$global.lb.has(dep);'],
|
|
91
89
|
)});`,
|
|
92
90
|
],
|
|
93
91
|
)});`,
|
|
94
92
|
'if (runnableEntry) {',
|
|
95
|
-
`$
|
|
93
|
+
`$parcel$global.bq = $parcel$global.bq.filter(${fnExpr(
|
|
96
94
|
env,
|
|
97
95
|
['i'],
|
|
98
96
|
['return i.b !== runnableEntry.b;'],
|
|
99
97
|
)});`,
|
|
100
98
|
'runnableEntry.r();',
|
|
101
|
-
'$
|
|
99
|
+
'$parcel$global.pq();',
|
|
102
100
|
'}',
|
|
103
101
|
],
|
|
104
102
|
)}
|
|
105
103
|
}
|
|
106
104
|
`;
|
|
107
105
|
|
|
108
|
-
const $
|
|
109
|
-
function $
|
|
106
|
+
const $parcel$export = `
|
|
107
|
+
function $parcel$export(e, n, v, s) {
|
|
110
108
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
111
109
|
}
|
|
112
110
|
`;
|
|
113
111
|
|
|
114
|
-
const $
|
|
115
|
-
function $
|
|
112
|
+
const $parcel$exportWildcard = `
|
|
113
|
+
function $parcel$exportWildcard(dest, source) {
|
|
116
114
|
Object.keys(source).forEach(function(key) {
|
|
117
115
|
if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) {
|
|
118
116
|
return;
|
|
@@ -130,20 +128,20 @@ function $atlaspack$exportWildcard(dest, source) {
|
|
|
130
128
|
}
|
|
131
129
|
`;
|
|
132
130
|
|
|
133
|
-
const $
|
|
134
|
-
function $
|
|
131
|
+
const $parcel$interopDefault = `
|
|
132
|
+
function $parcel$interopDefault(a) {
|
|
135
133
|
return a && a.__esModule ? a.default : a;
|
|
136
134
|
}
|
|
137
135
|
`;
|
|
138
136
|
|
|
139
|
-
const $
|
|
137
|
+
const $parcel$global = (env: Environment): string => {
|
|
140
138
|
if (env.supports('global-this')) {
|
|
141
139
|
return `
|
|
142
|
-
var $
|
|
140
|
+
var $parcel$global = globalThis;
|
|
143
141
|
`;
|
|
144
142
|
}
|
|
145
143
|
return `
|
|
146
|
-
var $
|
|
144
|
+
var $parcel$global =
|
|
147
145
|
typeof globalThis !== 'undefined'
|
|
148
146
|
? globalThis
|
|
149
147
|
: typeof self !== 'undefined'
|
|
@@ -156,16 +154,16 @@ const $atlaspack$global = (env: Environment): string => {
|
|
|
156
154
|
`;
|
|
157
155
|
};
|
|
158
156
|
|
|
159
|
-
const $
|
|
160
|
-
function $
|
|
157
|
+
const $parcel$defineInteropFlag = `
|
|
158
|
+
function $parcel$defineInteropFlag(a) {
|
|
161
159
|
Object.defineProperty(a, '__esModule', {value: true, configurable: true});
|
|
162
160
|
}
|
|
163
161
|
`;
|
|
164
162
|
|
|
165
163
|
export const helpers = {
|
|
166
|
-
$
|
|
167
|
-
$
|
|
168
|
-
$
|
|
169
|
-
$
|
|
170
|
-
$
|
|
164
|
+
$parcel$export,
|
|
165
|
+
$parcel$exportWildcard,
|
|
166
|
+
$parcel$interopDefault,
|
|
167
|
+
$parcel$global,
|
|
168
|
+
$parcel$defineInteropFlag,
|
|
171
169
|
};
|
package/src/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import {DevPackager} from './DevPackager';
|
|
|
15
15
|
import {ScopeHoistingPackager} from './ScopeHoistingPackager';
|
|
16
16
|
|
|
17
17
|
type JSPackagerConfig = {|
|
|
18
|
-
|
|
18
|
+
parcelRequireName: string,
|
|
19
19
|
unstable_asyncBundleRuntime: boolean,
|
|
20
20
|
|};
|
|
21
21
|
|
|
@@ -50,8 +50,8 @@ export default (new Packager({
|
|
|
50
50
|
);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
// Generate a name for the global
|
|
54
|
-
// This allows multiple
|
|
53
|
+
// Generate a name for the global parcelRequire function that is unique to this project.
|
|
54
|
+
// This allows multiple parcel builds to coexist on the same page.
|
|
55
55
|
let packageName = await config.getConfigFrom(
|
|
56
56
|
options.projectRoot + '/index',
|
|
57
57
|
[],
|
|
@@ -62,7 +62,7 @@ export default (new Packager({
|
|
|
62
62
|
|
|
63
63
|
let name = packageName?.contents?.name ?? '';
|
|
64
64
|
return {
|
|
65
|
-
|
|
65
|
+
parcelRequireName: 'parcelRequire' + hashString(name).slice(-4),
|
|
66
66
|
unstable_asyncBundleRuntime: Boolean(
|
|
67
67
|
conf?.contents?.unstable_asyncBundleRuntime,
|
|
68
68
|
),
|
|
@@ -96,14 +96,14 @@ export default (new Packager({
|
|
|
96
96
|
options,
|
|
97
97
|
bundleGraph,
|
|
98
98
|
bundle,
|
|
99
|
-
nullthrows(config).
|
|
99
|
+
nullthrows(config).parcelRequireName,
|
|
100
100
|
nullthrows(config).unstable_asyncBundleRuntime,
|
|
101
101
|
)
|
|
102
102
|
: new DevPackager(
|
|
103
103
|
options,
|
|
104
104
|
bundleGraph,
|
|
105
105
|
bundle,
|
|
106
|
-
nullthrows(config).
|
|
106
|
+
nullthrows(config).parcelRequireName,
|
|
107
107
|
);
|
|
108
108
|
|
|
109
109
|
({contents, map} = await packager.package());
|
package/src/utils.js
CHANGED
|
@@ -3,15 +3,15 @@ import type {BundleGraph, Dependency, NamedBundle} from '@atlaspack/types';
|
|
|
3
3
|
import type SourceMap from '@parcel/source-map';
|
|
4
4
|
import nullthrows from 'nullthrows';
|
|
5
5
|
|
|
6
|
-
// This replaces
|
|
7
|
-
//
|
|
6
|
+
// This replaces __parcel__require__ references left by the transformer with
|
|
7
|
+
// parcelRequire calls of the resolved asset id. This lets runtimes work within
|
|
8
8
|
// script bundles, which must be outside the bundle wrapper so their variables are global.
|
|
9
9
|
export function replaceScriptDependencies(
|
|
10
10
|
bundleGraph: BundleGraph<NamedBundle>,
|
|
11
11
|
bundle: NamedBundle,
|
|
12
12
|
code: string,
|
|
13
13
|
map: ?SourceMap,
|
|
14
|
-
|
|
14
|
+
parcelRequireName: string,
|
|
15
15
|
): string {
|
|
16
16
|
let entry = nullthrows(bundle.getMainEntry());
|
|
17
17
|
let dependencies = bundleGraph.getDependencies(entry);
|
|
@@ -19,34 +19,31 @@ export function replaceScriptDependencies(
|
|
|
19
19
|
let lineCount = 0;
|
|
20
20
|
let offset = 0;
|
|
21
21
|
let columnStartIndex = 0;
|
|
22
|
-
code = code.replace(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return '\n';
|
|
29
|
-
}
|
|
22
|
+
code = code.replace(/\n|__parcel__require__\(['"](.*?)['"]\)/g, (m, s, i) => {
|
|
23
|
+
if (m === '\n') {
|
|
24
|
+
columnStartIndex = i + offset + 1;
|
|
25
|
+
lineCount++;
|
|
26
|
+
return '\n';
|
|
27
|
+
}
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
29
|
+
let dep = nullthrows(dependencies.find(d => getSpecifier(d) === s));
|
|
30
|
+
let resolved = nullthrows(bundleGraph.getResolvedAsset(dep, bundle));
|
|
31
|
+
let publicId = bundleGraph.getAssetPublicId(resolved);
|
|
32
|
+
let replacement = `${parcelRequireName}("${publicId}")`;
|
|
33
|
+
if (map) {
|
|
34
|
+
let lengthDifference = replacement.length - m.length;
|
|
35
|
+
if (lengthDifference !== 0) {
|
|
36
|
+
map.offsetColumns(
|
|
37
|
+
lineCount + 1,
|
|
38
|
+
i + offset - columnStartIndex + m.length,
|
|
39
|
+
lengthDifference,
|
|
40
|
+
);
|
|
41
|
+
offset += lengthDifference;
|
|
45
42
|
}
|
|
43
|
+
}
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
);
|
|
45
|
+
return replacement;
|
|
46
|
+
});
|
|
50
47
|
|
|
51
48
|
return code;
|
|
52
49
|
}
|