@atlaspack/packager-js 2.14.5-canary.137 → 2.14.5-canary.139

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
@@ -0,0 +1,11 @@
1
+ import type { Environment } from '@atlaspack/types';
2
+ export declare const prelude: (parcelRequireName: string) => string;
3
+ export declare const fnExpr: (env: Environment, params: Array<string>, body: Array<string>) => string;
4
+ export declare const bundleQueuePrelude: (env: Environment) => string;
5
+ export declare const helpers: {
6
+ readonly $parcel$export: "\nfunction $parcel$export(e, n, v, s) {\n Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});\n}\n";
7
+ readonly $parcel$exportWildcard: "\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n }\n });\n });\n\n return dest;\n}\n";
8
+ readonly $parcel$interopDefault: "\nfunction $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n";
9
+ readonly $parcel$global: (env: Environment) => string;
10
+ readonly $parcel$defineInteropFlag: "\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true, configurable: true});\n}\n";
11
+ };
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { Packager } from '@atlaspack/plugin';
2
+ declare const _default: Packager<unknown, unknown>;
3
+ export default _default;
package/lib/index.js CHANGED
@@ -77,8 +77,10 @@ var _default = exports.default = new (_plugin().Packager)({
77
77
  });
78
78
  let name = (packageName === null || packageName === void 0 ? void 0 : packageName.contents) ?? '';
79
79
  return {
80
+ // @ts-expect-error TS2345
80
81
  parcelRequireName: 'parcelRequire' + (0, _rust().hashString)(name).slice(-4),
81
- unstable_asyncBundleRuntime: Boolean(conf === null || conf === void 0 || (_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.unstable_asyncBundleRuntime)
82
+ unstable_asyncBundleRuntime: Boolean( // @ts-expect-error TS2339
83
+ conf === null || conf === void 0 || (_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.unstable_asyncBundleRuntime)
82
84
  };
83
85
  },
84
86
  async package({
@@ -101,15 +103,7 @@ var _default = exports.default = new (_plugin().Packager)({
101
103
  }
102
104
  }
103
105
  if (contents == null) {
104
- let packager = bundle.env.shouldScopeHoist ? new _ScopeHoistingPackager.ScopeHoistingPackager(options, bundleGraph, bundle,
105
- // $FlowFixMe
106
- // $FlowFixMe
107
- (0, _nullthrows().default)(config).parcelRequireName,
108
- // $FlowFixMe
109
- (0, _nullthrows().default)(config).unstable_asyncBundleRuntime, logger) : new _DevPackager.DevPackager(options, bundleGraph, bundle,
110
- // $FlowFixMe
111
- // $FlowFixMe
112
- (0, _nullthrows().default)(config).parcelRequireName);
106
+ let packager = bundle.env.shouldScopeHoist ? new _ScopeHoistingPackager.ScopeHoistingPackager(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName, (0, _nullthrows().default)(config).unstable_asyncBundleRuntime, logger) : new _DevPackager.DevPackager(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName);
113
107
  ({
114
108
  contents,
115
109
  map
package/lib/utils.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { BundleGraph, Dependency, NamedBundle } from '@atlaspack/types';
2
+ import type SourceMap from '@parcel/source-map';
3
+ export declare function replaceScriptDependencies(bundleGraph: BundleGraph<NamedBundle>, bundle: NamedBundle, code: string, map: SourceMap | null | undefined, parcelRequireName: string): string;
4
+ export declare function getSpecifier(dep: Dependency): string;
5
+ export declare function isValidIdentifier(id: string): boolean;
6
+ export declare function makeValidIdentifier(name: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/packager-js",
3
- "version": "2.14.5-canary.137+069de478e",
3
+ "version": "2.14.5-canary.139+d2fd84977",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -9,23 +9,27 @@
9
9
  "type": "git",
10
10
  "url": "https://github.com/atlassian-labs/atlaspack.git"
11
11
  },
12
- "main": "lib/index.js",
13
- "source": "src/index.js",
12
+ "main": "./lib/index.js",
13
+ "source": "./src/index.ts",
14
+ "types": "./lib/index.d.ts",
14
15
  "engines": {
15
16
  "node": ">= 16.0.0"
16
17
  },
17
18
  "dependencies": {
18
- "@atlaspack/diagnostic": "2.14.1-canary.205+069de478e",
19
- "@atlaspack/feature-flags": "2.14.1-canary.205+069de478e",
20
- "@atlaspack/plugin": "2.14.5-canary.137+069de478e",
21
- "@atlaspack/rust": "3.2.1-canary.137+069de478e",
22
- "@atlaspack/types": "2.14.5-canary.137+069de478e",
23
- "@atlaspack/utils": "2.14.5-canary.137+069de478e",
19
+ "@atlaspack/diagnostic": "2.14.1-canary.207+d2fd84977",
20
+ "@atlaspack/feature-flags": "2.14.1-canary.207+d2fd84977",
21
+ "@atlaspack/plugin": "2.14.5-canary.139+d2fd84977",
22
+ "@atlaspack/rust": "3.2.1-canary.139+d2fd84977",
23
+ "@atlaspack/types": "2.14.5-canary.139+d2fd84977",
24
+ "@atlaspack/utils": "2.14.5-canary.139+d2fd84977",
24
25
  "@parcel/source-map": "^2.1.1",
25
26
  "globals": "^13.2.0",
26
27
  "nullthrows": "^1.1.1",
27
28
  "outdent": "^0.8.0"
28
29
  },
29
30
  "type": "commonjs",
30
- "gitHead": "069de478e64fb5889f6f2ce023eb510782767fbd"
31
- }
31
+ "scripts": {
32
+ "check-ts": "tsc --emitDeclarationOnly --rootDir src"
33
+ },
34
+ "gitHead": "d2fd849770fe6305e9c694bd97b1bd905abd9d94"
35
+ }
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import type {
3
2
  ScopeHoistingPackager,
4
3
  OutputFormat,
@@ -1,4 +1,3 @@
1
- // @flow strict-local
2
1
  import type {BundleGraph, PluginOptions, NamedBundle} from '@atlaspack/types';
3
2
 
4
3
  import {
@@ -37,7 +36,10 @@ export class DevPackager {
37
36
  this.parcelRequireName = parcelRequireName;
38
37
  }
39
38
 
40
- async package(): Promise<{|contents: string, map: ?SourceMap|}> {
39
+ async package(): Promise<{
40
+ contents: string;
41
+ map: SourceMap | null | undefined;
42
+ }> {
41
43
  // Load assets
42
44
  let queue = new PromiseQueue({maxConcurrent: 32});
43
45
  this.bundle.traverseAssets((asset) => {
@@ -59,7 +61,13 @@ export class DevPackager {
59
61
 
60
62
  let prefix = this.getPrefix();
61
63
  let lineOffset = countLines(prefix);
62
- let script: ?{|code: string, mapBuffer: ?Buffer|} = null;
64
+ let script:
65
+ | {
66
+ code: string;
67
+ mapBuffer: Buffer | null | undefined;
68
+ }
69
+ | null
70
+ | undefined = null;
63
71
 
64
72
  this.bundle.traverse((node) => {
65
73
  let wrapped = first ? '' : ',';
@@ -94,11 +102,12 @@ export class DevPackager {
94
102
  this.bundle.env.sourceType === 'script' &&
95
103
  asset === this.bundle.getMainEntry()
96
104
  ) {
105
+ // @ts-expect-error TS2322
97
106
  script = results[i++];
98
107
  return;
99
108
  }
100
109
 
101
- let deps = {};
110
+ let deps: Record<string, any> = {};
102
111
  let dependencies = this.bundleGraph.getDependencies(asset);
103
112
  for (let dep of dependencies) {
104
113
  let resolved = this.bundleGraph.getResolvedAsset(dep, this.bundle);
@@ -125,6 +134,7 @@ export class DevPackager {
125
134
  }
126
135
  }
127
136
 
137
+ // @ts-expect-error TS2339
128
138
  let {code, mapBuffer} = results[i];
129
139
  let output = code || '';
130
140
  wrapped +=
@@ -205,6 +215,7 @@ export class DevPackager {
205
215
  // runtimes with a parcelRequire call.
206
216
  if (this.bundle.env.sourceType === 'script' && script) {
207
217
  let entryMap;
218
+ // @ts-expect-error TS2339
208
219
  let mapBuffer = script.mapBuffer;
209
220
  if (mapBuffer) {
210
221
  entryMap = new SourceMap(this.options.projectRoot, mapBuffer);
@@ -212,11 +223,13 @@ export class DevPackager {
212
223
  contents += replaceScriptDependencies(
213
224
  this.bundleGraph,
214
225
  this.bundle,
226
+ // @ts-expect-error TS2339
215
227
  script.code,
216
228
  entryMap,
217
229
  this.parcelRequireName,
218
230
  );
219
231
  if (this.bundle.env.sourceMap && entryMap) {
232
+ // @ts-expect-error TS2551
220
233
  map.addSourceMap(entryMap, lineOffset);
221
234
  }
222
235
  }
@@ -228,7 +241,7 @@ export class DevPackager {
228
241
  }
229
242
 
230
243
  getPrefix(): string {
231
- let interpreter: ?string;
244
+ let interpreter: string | null | undefined;
232
245
  let mainEntry = this.bundle.getMainEntry();
233
246
  if (mainEntry && this.isEntry() && !this.bundle.target.env.isBrowser()) {
234
247
  let _interpreter = mainEntry.meta.interpreter;
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import type {
3
2
  ScopeHoistingPackager,
4
3
  OutputFormat,
@@ -18,7 +17,7 @@ export class ESMOutputFormat implements OutputFormat {
18
17
  for (let [source, specifiers] of this.packager.externals) {
19
18
  let defaultSpecifier = null;
20
19
  let namespaceSpecifier = null;
21
- let namedSpecifiers = [];
20
+ let namedSpecifiers: Array<string> = [];
22
21
  for (let [imported, symbol] of specifiers) {
23
22
  if (imported === 'default' /* || isCommonJS*/) {
24
23
  defaultSpecifier = symbol;
@@ -77,7 +76,7 @@ export class ESMOutputFormat implements OutputFormat {
77
76
  buildBundlePostlude(): [string, number] {
78
77
  let res = '';
79
78
  let lines = 0;
80
- let exportSpecifiers = [];
79
+ let exportSpecifiers: Array<string> = [];
81
80
  for (let {
82
81
  asset,
83
82
  exportSymbol,
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import type {
3
2
  ScopeHoistingPackager,
4
3
  OutputFormat,