@atlaspack/packager-js 2.14.5-canary.25 → 2.14.5-canary.250

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.
@@ -12,12 +12,12 @@
12
12
  typeof globalThis !== 'undefined'
13
13
  ? globalThis
14
14
  : typeof self !== 'undefined'
15
- ? self
16
- : typeof window !== 'undefined'
17
- ? window
18
- : typeof global !== 'undefined'
19
- ? global
20
- : {};
15
+ ? self
16
+ : typeof window !== 'undefined'
17
+ ? window
18
+ : typeof global !== 'undefined'
19
+ ? global
20
+ : {};
21
21
  /* eslint-enable no-undef */
22
22
 
23
23
  // Save the require from previous bundle to this closure if any
@@ -1,7 +1,6 @@
1
- // @flow strict-local
2
1
  import type {Environment} from '@atlaspack/types';
3
2
 
4
- export const prelude = (parcelRequireName: string): string => `
3
+ export const preludeOld = (parcelRequireName: string): string => `
5
4
  var $parcel$modules = {};
6
5
  var $parcel$inits = {};
7
6
 
@@ -35,6 +34,41 @@ if (parcelRequire == null) {
35
34
  var parcelRegister = parcelRequire.register;
36
35
  `;
37
36
 
37
+ export const preludeNew = (parcelRequireName: string): string => `
38
+ var $parcel$modules = {};
39
+ var $parcel$inits = {};
40
+
41
+ var parcelRequire = $parcel$global[${JSON.stringify(parcelRequireName)}];
42
+
43
+ if (parcelRequire == null) {
44
+ parcelRequire = function(id) {
45
+ var mod = $parcel$modules[id];
46
+ if (mod !== undefined) {
47
+ return mod.exports;
48
+ }
49
+ var init = $parcel$inits[id];
50
+ if (init !== undefined) {
51
+ delete $parcel$inits[id];
52
+ var module = {id: id, exports: {}};
53
+ $parcel$modules[id] = module;
54
+ init.call(module.exports, module, module.exports);
55
+ return module.exports;
56
+ }
57
+ var err = new Error("Cannot find module '" + id + "'");
58
+ err.code = 'MODULE_NOT_FOUND';
59
+ throw err;
60
+ };
61
+
62
+ parcelRequire.register = function register(id, init) {
63
+ $parcel$inits[id] = init;
64
+ };
65
+
66
+ $parcel$global[${JSON.stringify(parcelRequireName)}] = parcelRequire;
67
+ }
68
+
69
+ var parcelRegister = parcelRequire.register;
70
+ `;
71
+
38
72
  export const fnExpr = (
39
73
  env: Environment,
40
74
  params: Array<string>,
@@ -166,4 +200,4 @@ export const helpers = {
166
200
  $parcel$interopDefault,
167
201
  $parcel$global,
168
202
  $parcel$defineInteropFlag,
169
- };
203
+ } as const;
@@ -1,24 +1,27 @@
1
- // @flow strict-local
2
- import type {Async} from '@atlaspack/types';
1
+ import type {Async, BundleResult} from '@atlaspack/types';
3
2
  import type SourceMap from '@parcel/source-map';
4
3
  import {Packager} from '@atlaspack/plugin';
5
4
  import {
6
5
  replaceInlineReferences,
7
6
  replaceURLReferences,
8
7
  validateSchema,
9
- type SchemaEntity,
8
+ SchemaEntity,
9
+ debugTools,
10
10
  } from '@atlaspack/utils';
11
11
  import {encodeJSONKeyComponent} from '@atlaspack/diagnostic';
12
12
  import {hashString} from '@atlaspack/rust';
13
13
  import nullthrows from 'nullthrows';
14
14
  import {DevPackager} from './DevPackager';
15
- import {ScopeHoistingPackager} from './ScopeHoistingPackager';
15
+ import {
16
+ type PackageResult as ScopeHoistingPackageResult,
17
+ ScopeHoistingPackager,
18
+ } from './ScopeHoistingPackager';
16
19
 
17
- type JSPackagerConfig = {|
18
- parcelRequireName: string,
19
- unstable_asyncBundleRuntime: boolean,
20
- unstable_forceSkipWrapAssets: Array<string>,
21
- |};
20
+ type JSPackagerConfig = {
21
+ parcelRequireName: string;
22
+ unstable_asyncBundleRuntime: boolean;
23
+ unstable_manualStaticBindingExports: string[] | null;
24
+ };
22
25
 
23
26
  const CONFIG_SCHEMA: SchemaEntity = {
24
27
  type: 'object',
@@ -26,7 +29,7 @@ const CONFIG_SCHEMA: SchemaEntity = {
26
29
  unstable_asyncBundleRuntime: {
27
30
  type: 'boolean',
28
31
  },
29
- unstable_forceSkipWrapAssets: {
32
+ unstable_manualStaticBindingExports: {
30
33
  type: 'array',
31
34
  items: {
32
35
  type: 'string',
@@ -36,10 +39,13 @@ const CONFIG_SCHEMA: SchemaEntity = {
36
39
  additionalProperties: false,
37
40
  };
38
41
 
39
- export default (new Packager({
42
+ export default new Packager({
40
43
  async loadConfig({config, options}): Promise<JSPackagerConfig> {
41
44
  let packageKey = '@atlaspack/packager-js';
42
- let conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
45
+ let conf = await config.getConfigFrom<{
46
+ unstable_asyncBundleRuntime?: boolean;
47
+ unstable_manualStaticBindingExports?: string[];
48
+ }>(options.projectRoot + '/index', [], {
43
49
  packageKey,
44
50
  });
45
51
 
@@ -59,7 +65,7 @@ export default (new Packager({
59
65
 
60
66
  // Generate a name for the global parcelRequire function that is unique to this project.
61
67
  // This allows multiple parcel builds to coexist on the same page.
62
- let packageName = await config.getConfigFrom(
68
+ let packageName = await config.getConfigFrom<string>(
63
69
  options.projectRoot + '/index',
64
70
  [],
65
71
  {
@@ -73,8 +79,8 @@ export default (new Packager({
73
79
  unstable_asyncBundleRuntime: Boolean(
74
80
  conf?.contents?.unstable_asyncBundleRuntime,
75
81
  ),
76
- unstable_forceSkipWrapAssets:
77
- conf?.contents?.unstable_forceSkipWrapAssets ?? [],
82
+ unstable_manualStaticBindingExports:
83
+ conf?.contents?.unstable_manualStaticBindingExports ?? null,
78
84
  };
79
85
  },
80
86
  async package({
@@ -89,6 +95,8 @@ export default (new Packager({
89
95
  // If this is a non-module script, and there is only one asset with no dependencies,
90
96
  // then we don't need to package at all and can pass through the original code un-wrapped.
91
97
  let contents, map;
98
+ let scopeHoistingStats: ScopeHoistingPackageResult['scopeHoistingStats'];
99
+
92
100
  if (bundle.env.sourceType === 'script') {
93
101
  let entries = bundle.getEntryAssets();
94
102
  if (
@@ -101,24 +109,31 @@ export default (new Packager({
101
109
  }
102
110
 
103
111
  if (contents == null) {
104
- let packager = bundle.env.shouldScopeHoist
105
- ? new ScopeHoistingPackager(
106
- options,
107
- bundleGraph,
108
- bundle,
109
- nullthrows(config).parcelRequireName,
110
- nullthrows(config).unstable_asyncBundleRuntime,
111
- nullthrows(config).unstable_forceSkipWrapAssets,
112
- logger,
113
- )
114
- : new DevPackager(
115
- options,
116
- bundleGraph,
117
- bundle,
118
- nullthrows(config).parcelRequireName,
119
- );
120
-
121
- ({contents, map} = await packager.package());
112
+ if (bundle.env.shouldScopeHoist) {
113
+ let packager = new ScopeHoistingPackager(
114
+ options,
115
+ bundleGraph,
116
+ bundle,
117
+ nullthrows(config).parcelRequireName,
118
+ nullthrows(config).unstable_asyncBundleRuntime,
119
+ nullthrows(config).unstable_manualStaticBindingExports,
120
+ logger,
121
+ );
122
+
123
+ let packageResult = await packager.package();
124
+ ({contents, map} = packageResult);
125
+ scopeHoistingStats = packageResult.scopeHoistingStats;
126
+ } else {
127
+ let packager = new DevPackager(
128
+ options,
129
+ bundleGraph,
130
+ bundle,
131
+ nullthrows(config).parcelRequireName,
132
+ );
133
+
134
+ let packageResult = await packager.package();
135
+ ({contents, map} = packageResult);
136
+ }
122
137
  }
123
138
 
124
139
  contents += '\n' + (await getSourceMapSuffix(getSourceMapReference, map));
@@ -135,7 +150,7 @@ export default (new Packager({
135
150
  }));
136
151
  }
137
152
 
138
- return replaceInlineReferences({
153
+ let result = await replaceInlineReferences({
139
154
  bundle,
140
155
  bundleGraph,
141
156
  contents,
@@ -146,12 +161,20 @@ export default (new Packager({
146
161
  getInlineBundleContents,
147
162
  map,
148
163
  });
164
+
165
+ if (debugTools['scope-hoisting-stats']) {
166
+ return {...result, scopeHoistingStats};
167
+ }
168
+
169
+ return result;
149
170
  },
150
- }): Packager);
171
+ }) as Packager<unknown, unknown>;
151
172
 
152
173
  async function getSourceMapSuffix(
153
- getSourceMapReference: (?SourceMap) => Async<?string>,
154
- map: ?SourceMap,
174
+ getSourceMapReference: (
175
+ arg1?: SourceMap | null | undefined,
176
+ ) => Async<string | null | undefined>,
177
+ map?: SourceMap | null,
155
178
  ): Promise<string> {
156
179
  let sourcemapReference = await getSourceMapReference(map);
157
180
  if (sourcemapReference != null) {
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import type {BundleGraph, Dependency, NamedBundle} from '@atlaspack/types';
3
2
  import type SourceMap from '@parcel/source-map';
4
3
  import nullthrows from 'nullthrows';
@@ -10,7 +9,7 @@ export function replaceScriptDependencies(
10
9
  bundleGraph: BundleGraph<NamedBundle>,
11
10
  bundle: NamedBundle,
12
11
  code: string,
13
- map: ?SourceMap,
12
+ map: SourceMap | null | undefined,
14
13
  parcelRequireName: string,
15
14
  ): string {
16
15
  let entry = nullthrows(bundle.getMainEntry());
package/tsconfig.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "extends": "../../../tsconfig.base.json",
3
+ "include": ["src"],
4
+ "compilerOptions": {
5
+ "composite": true
6
+ },
7
+ "references": [
8
+ {
9
+ "path": "../../core/diagnostic/tsconfig.json"
10
+ },
11
+ {
12
+ "path": "../../core/feature-flags/tsconfig.json"
13
+ },
14
+ {
15
+ "path": "../../core/plugin/tsconfig.json"
16
+ },
17
+ {
18
+ "path": "../../core/rust/tsconfig.json"
19
+ },
20
+ {
21
+ "path": "../../core/types/tsconfig.json"
22
+ },
23
+ {
24
+ "path": "../../core/utils/tsconfig.json"
25
+ }
26
+ ]
27
+ }