@atlaspack/packager-js 2.12.1-dev.3368 → 2.12.1-dev.3401

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/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 = (atlaspackRequireName: string): string => `
5
- var $atlaspack$modules = {};
6
- var $atlaspack$inits = {};
7
-
8
- var atlaspackRequire = $atlaspack$global[${JSON.stringify(
9
- atlaspackRequireName,
10
- )}];
11
-
12
- if (atlaspackRequire == null) {
13
- atlaspackRequire = function(id) {
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 $atlaspack$inits) {
18
- var init = $atlaspack$inits[id];
19
- delete $atlaspack$inits[id];
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
- $atlaspack$modules[id] = module;
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
- atlaspackRequire.register = function register(id, init) {
31
- $atlaspack$inits[id] = init;
28
+ parcelRequire.register = function register(id, init) {
29
+ $parcel$inits[id] = init;
32
30
  };
33
31
 
34
- $atlaspack$global[${JSON.stringify(atlaspackRequireName)}] = atlaspackRequire;
32
+ $parcel$global[${JSON.stringify(parcelRequireName)}] = parcelRequire;
35
33
  }
36
34
 
37
- var atlaspackRegister = atlaspackRequire.register;
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 (!$atlaspack$global.lb) {
53
+ if (!$parcel$global.lb) {
56
54
  // Set of loaded bundles
57
- $atlaspack$global.lb = new Set();
55
+ $parcel$global.lb = new Set();
58
56
  // Queue of bundles to execute once they're dep bundles are loaded
59
- $atlaspack$global.bq = [];
57
+ $parcel$global.bq = [];
60
58
 
61
59
  // Register loaded bundle
62
- $atlaspack$global.rlb = ${fnExpr(
60
+ $parcel$global.rlb = ${fnExpr(
63
61
  env,
64
62
  ['bundle'],
65
- ['$atlaspack$global.lb.add(bundle);', '$atlaspack$global.pq();'],
63
+ ['$parcel$global.lb.add(bundle);', '$parcel$global.pq();'],
66
64
  )}
67
65
 
68
66
  // Run when ready
69
- $atlaspack$global.rwr = ${fnExpr(
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
- ['$atlaspack$global.bq.push({b, r, d});', '$atlaspack$global.pq();'],
73
+ ['$parcel$global.bq.push({b, r, d});', '$parcel$global.pq();'],
76
74
  )}
77
75
 
78
76
  // Process queue
79
- $atlaspack$global.pq = ${fnExpr(
77
+ $parcel$global.pq = ${fnExpr(
80
78
  env,
81
79
  [],
82
80
  [
83
- `var runnableEntry = $atlaspack$global.bq.find(${fnExpr(
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 $atlaspack$global.lb.has(dep);'],
88
+ ['return $parcel$global.lb.has(dep);'],
91
89
  )});`,
92
90
  ],
93
91
  )});`,
94
92
  'if (runnableEntry) {',
95
- `$atlaspack$global.bq = $atlaspack$global.bq.filter(${fnExpr(
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
- '$atlaspack$global.pq();',
99
+ '$parcel$global.pq();',
102
100
  '}',
103
101
  ],
104
102
  )}
105
103
  }
106
104
  `;
107
105
 
108
- const $atlaspack$export = `
109
- function $atlaspack$export(e, n, v, s) {
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 $atlaspack$exportWildcard = `
115
- function $atlaspack$exportWildcard(dest, source) {
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 $atlaspack$interopDefault = `
134
- function $atlaspack$interopDefault(a) {
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 $atlaspack$global = (env: Environment): string => {
137
+ const $parcel$global = (env: Environment): string => {
140
138
  if (env.supports('global-this')) {
141
139
  return `
142
- var $atlaspack$global = globalThis;
140
+ var $parcel$global = globalThis;
143
141
  `;
144
142
  }
145
143
  return `
146
- var $atlaspack$global =
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 $atlaspack$defineInteropFlag = `
160
- function $atlaspack$defineInteropFlag(a) {
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
- $atlaspack$export,
167
- $atlaspack$exportWildcard,
168
- $atlaspack$interopDefault,
169
- $atlaspack$global,
170
- $atlaspack$defineInteropFlag,
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
- atlaspackRequireName: string,
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 atlaspackRequire function that is unique to this project.
54
- // This allows multiple atlaspack builds to coexist on the same page.
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
- atlaspackRequireName: 'atlaspackRequire' + hashString(name).slice(-4),
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).atlaspackRequireName,
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).atlaspackRequireName,
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 __atlaspack__require__ references left by the transformer with
7
- // atlaspackRequire calls of the resolved asset id. This lets runtimes work within
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
- atlaspackRequireName: string,
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
- /\n|__atlaspack__require__\(['"](.*?)['"]\)/g,
24
- (m, s, i) => {
25
- if (m === '\n') {
26
- columnStartIndex = i + offset + 1;
27
- lineCount++;
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
- let dep = nullthrows(dependencies.find(d => getSpecifier(d) === s));
32
- let resolved = nullthrows(bundleGraph.getResolvedAsset(dep, bundle));
33
- let publicId = bundleGraph.getAssetPublicId(resolved);
34
- let replacement = `${atlaspackRequireName}("${publicId}")`;
35
- if (map) {
36
- let lengthDifference = replacement.length - m.length;
37
- if (lengthDifference !== 0) {
38
- map.offsetColumns(
39
- lineCount + 1,
40
- i + offset - columnStartIndex + m.length,
41
- lengthDifference,
42
- );
43
- offset += lengthDifference;
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
- return replacement;
48
- },
49
- );
45
+ return replacement;
46
+ });
50
47
 
51
48
  return code;
52
49
  }