@atlaspack/core 2.12.1-canary.3443 → 2.12.1-canary.3445

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.
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.AssetCompat = void 0;
7
- var _Environment = _interopRequireDefault(require("../../public/Environment"));
8
- var _types = require("../../types");
7
+ var _Environment = _interopRequireDefault(require("../../../public/Environment"));
8
+ var _types = require("../../../types");
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
10
  class AssetCompat {
11
11
  // TODO: Type properly
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MutableDependencySymbols = exports.MutableAssetSymbols = exports.AssetSymbols = void 0;
7
+ class MutableDependencySymbols {
8
+ #symbols;
9
+ #locals;
10
+ get isCleared() {
11
+ return this.#symbols.size === 0;
12
+ }
13
+ constructor(inner) {
14
+ this.#symbols = new Map();
15
+ this.#locals = new Set();
16
+ for (const {
17
+ exported,
18
+ local,
19
+ loc,
20
+ isWeak
21
+ } of inner) {
22
+ this.set(exported, local, loc, isWeak);
23
+ }
24
+ }
25
+ ensure() {
26
+ throw new Error('MutableDependencySymbols.ensure()');
27
+ }
28
+ get(exportSymbol) {
29
+ return this.#symbols.get(exportSymbol);
30
+ }
31
+ hasExportSymbol(exportSymbol) {
32
+ return this.#symbols.has(exportSymbol);
33
+ }
34
+ hasLocalSymbol(local) {
35
+ return this.#locals.has(local);
36
+ }
37
+ exportSymbols() {
38
+ return this.#symbols.keys();
39
+ }
40
+ set(exportSymbol, local, loc, isWeak) {
41
+ this.#locals.add(local);
42
+ this.#symbols.set(exportSymbol, {
43
+ local,
44
+ loc,
45
+ meta: {},
46
+ isWeak: isWeak ?? false
47
+ });
48
+ }
49
+ delete(exportSymbol) {
50
+ let existing = this.#symbols.get(exportSymbol);
51
+ if (!existing) return;
52
+ this.#locals.delete(existing.local);
53
+ this.#symbols.delete(exportSymbol);
54
+ }
55
+
56
+ /*:: @@iterator(): Iterator<[Symbol, DependencyAssetSymbol]> { return ({}: any); } */
57
+ // $FlowFixMe Flow can't do computed properties
58
+ [Symbol.iterator]() {
59
+ return this.#symbols.values();
60
+ }
61
+ }
62
+
63
+ // TODO
64
+ exports.MutableDependencySymbols = MutableDependencySymbols;
65
+ class AssetSymbols extends Array {
66
+ // eslint-disable-next-line no-unused-vars
67
+ get() {}
68
+
69
+ // eslint-disable-next-line no-unused-vars
70
+ hasExportSymbol() {
71
+ throw new Error('AssetSymbols.hasExportSymbol');
72
+ }
73
+
74
+ // eslint-disable-next-line no-unused-vars
75
+ hasLocalSymbol() {
76
+ throw new Error('AssetSymbols.hasExportSymbol');
77
+ }
78
+ exportSymbols() {
79
+ return [];
80
+ }
81
+ }
82
+
83
+ // TODO
84
+ exports.AssetSymbols = AssetSymbols;
85
+ class MutableAssetSymbols extends AssetSymbols {
86
+ ensure() {}
87
+ set() {}
88
+
89
+ // eslint-disable-next-line no-unused-vars
90
+ delete() {}
91
+ }
92
+ exports.MutableAssetSymbols = MutableAssetSymbols;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.specifierTypeMap = exports.packageConditionsMap = exports.dependencyPriorityMap = exports.bundleBehaviorMap = exports.BitFlags = void 0;
7
+ /// BitFlags is used to map number/string types from napi types
8
+ class BitFlags {
9
+ #kv;
10
+ #vk;
11
+ constructor(source) {
12
+ this.#kv = source;
13
+ this.#vk = Object.fromEntries(
14
+ // $FlowFixMe
15
+ Object.entries(source).map(a => a.reverse()));
16
+ }
17
+ into(key) {
18
+ const found = this.#kv[key];
19
+ if (found === undefined) {
20
+ // $FlowFixMe
21
+ throw new Error(`Invalid BundleBehavior(${key})`);
22
+ }
23
+ return found;
24
+ }
25
+ intoArray(keys) {
26
+ return keys.map(key => this.into(key));
27
+ }
28
+ from(key) {
29
+ const found = this.#vk[key];
30
+ if (found === undefined) {
31
+ // $FlowFixMe
32
+ throw new Error(`Invalid BundleBehavior(${key})`);
33
+ }
34
+ return found;
35
+ }
36
+ fromArray(keys) {
37
+ return keys.map(key => this.from(key));
38
+ }
39
+ }
40
+ exports.BitFlags = BitFlags;
41
+ const bundleBehaviorMap = exports.bundleBehaviorMap = new BitFlags({
42
+ inline: 0,
43
+ isolated: 1
44
+ });
45
+ const dependencyPriorityMap = exports.dependencyPriorityMap = new BitFlags({
46
+ sync: 0,
47
+ parallel: 1,
48
+ lazy: 2,
49
+ conditional: 3
50
+ });
51
+ const packageConditionsMap = exports.packageConditionsMap = new BitFlags({
52
+ import: 0,
53
+ require: 1,
54
+ module: 2,
55
+ node: 3,
56
+ browser: 4,
57
+ worker: 5,
58
+ worklet: 6,
59
+ electron: 7,
60
+ development: 8,
61
+ production: 9,
62
+ types: 10,
63
+ default: 11,
64
+ style: 12,
65
+ sass: 13
66
+ });
67
+ const specifierTypeMap = exports.specifierTypeMap = new BitFlags({
68
+ esm: 0,
69
+ commonjs: 1,
70
+ url: 2,
71
+ custom: 3
72
+ });
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Dependency = void 0;
7
+ var _target = require("./target");
8
+ var _assetSymbols = require("./asset-symbols");
9
+ var _bitflags = require("./bitflags");
10
+ class Dependency {
11
+ get id() {
12
+ throw new Error('Dependency.id');
13
+ }
14
+ constructor(inner, env) {
15
+ this.env = env;
16
+ this.meta = inner.meta || {};
17
+ this.target = undefined;
18
+ if (inner.target) {
19
+ this.target = new _target.Target(inner.target, this.env);
20
+ }
21
+ if (!inner.bundleBehavior) {
22
+ this.bundleBehavior = undefined;
23
+ } else {
24
+ this.bundleBehavior = _bitflags.bundleBehaviorMap.from(inner.bundleBehavior);
25
+ }
26
+ this.bundleBehavior = undefined;
27
+ this.symbols = new _assetSymbols.MutableDependencySymbols(inner.symbols || []);
28
+ this.specifier = inner.specifier;
29
+ this.specifierType = _bitflags.specifierTypeMap.from(inner.specifierType);
30
+ this.priority = _bitflags.dependencyPriorityMap.from(inner.priority);
31
+ this.needsStableName = inner.needsStableName;
32
+ this.isOptional = inner.isOptional;
33
+ this.isEntry = inner.isEntry;
34
+ this.loc = inner.loc;
35
+ this.packageConditions = _bitflags.packageConditionsMap.fromArray(inner.packageConditions || []);
36
+ this.sourceAssetId = inner.sourceAssetId;
37
+ this.sourcePath = inner.sourcePath;
38
+ this.sourceAssetType = inner.sourceAssetType;
39
+ this.resolveFrom = inner.resolveFrom;
40
+ this.range = inner.range;
41
+ this.pipeline = inner.pipeline;
42
+ }
43
+ }
44
+ exports.Dependency = Dependency;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Environment = void 0;
7
+ class Environment {
8
+ constructor(inner) {
9
+ // TODO
10
+ this.id = '';
11
+ this.includeNodeModules = inner.includeNodeModules;
12
+ // $FlowFixMe
13
+ this.context = inner.context;
14
+ this.engines = inner.engines;
15
+ // $FlowFixMe
16
+ this.outputFormat = inner.outputFormat;
17
+ // $FlowFixMe
18
+ this.sourceType = inner.sourceType;
19
+ this.isLibrary = inner.isLibrary;
20
+ this.shouldOptimize = inner.shouldOptimize;
21
+ this.shouldScopeHoist = inner.shouldScopeHoist;
22
+ this.sourceMap = inner.sourceMap;
23
+ this.loc = inner.loc;
24
+ }
25
+
26
+ // TODO
27
+ isBrowser() {
28
+ return true;
29
+ }
30
+
31
+ // TODO
32
+ isNode() {
33
+ return false;
34
+ }
35
+
36
+ // TODO
37
+ isElectron() {
38
+ return false;
39
+ }
40
+
41
+ // TODO
42
+ isWorker() {
43
+ return false;
44
+ }
45
+
46
+ // TODO
47
+ isWorklet() {
48
+ return false;
49
+ }
50
+
51
+ // TODO
52
+ isIsolated() {
53
+ return false;
54
+ }
55
+
56
+ // TODO
57
+ // eslint-disable-next-line no-unused-vars
58
+ matchesEngines() {
59
+ return true;
60
+ }
61
+
62
+ // TODO
63
+ // eslint-disable-next-line no-unused-vars
64
+ supports() {
65
+ return true;
66
+ }
67
+ }
68
+ exports.Environment = Environment;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _assetCompat = require("./asset-compat");
7
+ Object.keys(_assetCompat).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _assetCompat[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _assetCompat[key];
14
+ }
15
+ });
16
+ });
17
+ var _assetSymbols = require("./asset-symbols");
18
+ Object.keys(_assetSymbols).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _assetSymbols[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _assetSymbols[key];
25
+ }
26
+ });
27
+ });
28
+ var _bitflags = require("./bitflags");
29
+ Object.keys(_bitflags).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _bitflags[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _bitflags[key];
36
+ }
37
+ });
38
+ });
39
+ var _dependency = require("./dependency");
40
+ Object.keys(_dependency).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _dependency[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _dependency[key];
47
+ }
48
+ });
49
+ });
50
+ var _environment = require("./environment");
51
+ Object.keys(_environment).forEach(function (key) {
52
+ if (key === "default" || key === "__esModule") return;
53
+ if (key in exports && exports[key] === _environment[key]) return;
54
+ Object.defineProperty(exports, key, {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _environment[key];
58
+ }
59
+ });
60
+ });
61
+ var _target = require("./target");
62
+ Object.keys(_target).forEach(function (key) {
63
+ if (key === "default" || key === "__esModule") return;
64
+ if (key in exports && exports[key] === _target[key]) return;
65
+ Object.defineProperty(exports, key, {
66
+ enumerable: true,
67
+ get: function () {
68
+ return _target[key];
69
+ }
70
+ });
71
+ });
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Target = void 0;
7
+ class Target {
8
+ constructor(inner, env) {
9
+ this.distDir = inner.distDir;
10
+ this.distEntry = inner.distEntry;
11
+ this.name = inner.name;
12
+ this.publicUrl = inner.publicUrl;
13
+ this.loc = inner.loc;
14
+ this.env = env;
15
+ }
16
+ }
17
+ exports.Target = Target;
@@ -48,7 +48,6 @@ function _module() {
48
48
  }
49
49
  var _compat = require("./compat");
50
50
  var _jsCallable = require("../jsCallable");
51
- var _Environment = _interopRequireDefault(require("../../public/Environment"));
52
51
  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); }
53
52
  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; }
54
53
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -87,7 +86,7 @@ class AtlaspackWorker {
87
86
  });
88
87
  runResolverResolve = (0, _jsCallable.jsCallable)(async ({
89
88
  key,
90
- dependency,
89
+ dependency: napiDependency,
91
90
  specifier,
92
91
  pipeline,
93
92
  projectRoot
@@ -101,6 +100,8 @@ class AtlaspackWorker {
101
100
  packageManager = new (_packageManager().NodePackageManager)(this.#fs, projectRoot);
102
101
  state.packageManager = packageManager;
103
102
  }
103
+ const env = new _compat.Environment(napiDependency.env);
104
+ const dependency = new _compat.Dependency(napiDependency, env);
104
105
  const defaultOptions = {
105
106
  get logger() {
106
107
  // $FlowFixMe
@@ -154,10 +155,7 @@ class AtlaspackWorker {
154
155
  isSource: true,
155
156
  searchPath: '',
156
157
  // $FlowFixMe This isn't correct to flow but is enough to satisfy the runtime checks
157
- env: new _Environment.default(dependency.env, {
158
- projectRoot,
159
- hmrOptions: undefined
160
- }),
158
+ env,
161
159
  invalidateOnFileChange() {},
162
160
  invalidateOnFileCreate() {},
163
161
  invalidateOnEnvChange() {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/core",
3
- "version": "2.12.1-canary.3443+15e45b97e",
3
+ "version": "2.12.1-canary.3445+ba8fb88af",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -20,20 +20,20 @@
20
20
  "check-ts": "tsc --noEmit index.d.ts"
21
21
  },
22
22
  "dependencies": {
23
- "@atlaspack/cache": "2.12.1-canary.3443+15e45b97e",
24
- "@atlaspack/diagnostic": "2.12.1-canary.3443+15e45b97e",
25
- "@atlaspack/events": "2.12.1-canary.3443+15e45b97e",
26
- "@atlaspack/feature-flags": "2.12.1-canary.3443+15e45b97e",
27
- "@atlaspack/fs": "2.12.1-canary.3443+15e45b97e",
28
- "@atlaspack/graph": "3.2.1-canary.3443+15e45b97e",
29
- "@atlaspack/logger": "2.12.1-canary.3443+15e45b97e",
30
- "@atlaspack/package-manager": "2.12.1-canary.3443+15e45b97e",
31
- "@atlaspack/plugin": "2.12.1-canary.3443+15e45b97e",
32
- "@atlaspack/profiler": "2.12.1-canary.3443+15e45b97e",
33
- "@atlaspack/rust": "2.12.1-canary.3443+15e45b97e",
34
- "@atlaspack/types": "2.12.1-canary.3443+15e45b97e",
35
- "@atlaspack/utils": "2.12.1-canary.3443+15e45b97e",
36
- "@atlaspack/workers": "2.12.1-canary.3443+15e45b97e",
23
+ "@atlaspack/cache": "2.12.1-canary.3445+ba8fb88af",
24
+ "@atlaspack/diagnostic": "2.12.1-canary.3445+ba8fb88af",
25
+ "@atlaspack/events": "2.12.1-canary.3445+ba8fb88af",
26
+ "@atlaspack/feature-flags": "2.12.1-canary.3445+ba8fb88af",
27
+ "@atlaspack/fs": "2.12.1-canary.3445+ba8fb88af",
28
+ "@atlaspack/graph": "3.2.1-canary.3445+ba8fb88af",
29
+ "@atlaspack/logger": "2.12.1-canary.3445+ba8fb88af",
30
+ "@atlaspack/package-manager": "2.12.1-canary.3445+ba8fb88af",
31
+ "@atlaspack/plugin": "2.12.1-canary.3445+ba8fb88af",
32
+ "@atlaspack/profiler": "2.12.1-canary.3445+ba8fb88af",
33
+ "@atlaspack/rust": "2.12.1-canary.3445+ba8fb88af",
34
+ "@atlaspack/types": "2.12.1-canary.3445+ba8fb88af",
35
+ "@atlaspack/utils": "2.12.1-canary.3445+ba8fb88af",
36
+ "@atlaspack/workers": "2.12.1-canary.3445+ba8fb88af",
37
37
  "@mischnic/json-sourcemap": "^0.1.0",
38
38
  "@parcel/source-map": "^2.1.1",
39
39
  "base-x": "^3.0.8",
@@ -57,5 +57,5 @@
57
57
  "browser": {
58
58
  "./src/serializerCore.js": "./src/serializerCore.browser.js"
59
59
  },
60
- "gitHead": "15e45b97efca8057803259d2b6362ac1f3e50567"
60
+ "gitHead": "ba8fb88af15c3c574f5de99f9fbc18470821d763"
61
61
  }
@@ -1,11 +1,11 @@
1
1
  // @flow
2
2
  import type {PluginOptions, BundleBehavior, AST} from '@atlaspack/types';
3
3
 
4
- import Environment from '../../public/Environment';
4
+ import Environment from '../../../public/Environment';
5
5
  import {
6
6
  BundleBehaviorNames,
7
7
  BundleBehavior as BundleBehaviorMap,
8
- } from '../../types';
8
+ } from '../../../types';
9
9
 
10
10
  export type InnerAsset = {|
11
11
  id: string,
@@ -0,0 +1,132 @@
1
+ // @flow
2
+
3
+ import type {Symbol as NapiSymbol} from '@atlaspack/rust';
4
+ import type {
5
+ AssetSymbols as ClassicAssetSymbols,
6
+ MutableAssetSymbols as ClassicMutableAssetSymbols,
7
+ MutableDependencySymbols as ClassicMutableDependencySymbols,
8
+ Symbol,
9
+ SourceLocation,
10
+ Meta,
11
+ } from '@atlaspack/types';
12
+
13
+ export class MutableDependencySymbols
14
+ implements ClassicMutableDependencySymbols
15
+ {
16
+ #symbols: Map<Symbol, DependencyAssetSymbol>;
17
+ #locals: Set<Symbol>;
18
+
19
+ get isCleared(): boolean {
20
+ return this.#symbols.size === 0;
21
+ }
22
+
23
+ constructor(inner: NapiSymbol[]) {
24
+ this.#symbols = new Map();
25
+ this.#locals = new Set();
26
+ for (const {exported, local, loc, isWeak} of inner) {
27
+ this.set(exported, local, loc, isWeak);
28
+ }
29
+ }
30
+
31
+ ensure(): void {
32
+ throw new Error('MutableDependencySymbols.ensure()');
33
+ }
34
+
35
+ get(exportSymbol: Symbol): ?DependencyAssetSymbol {
36
+ return this.#symbols.get(exportSymbol);
37
+ }
38
+
39
+ hasExportSymbol(exportSymbol: Symbol): boolean {
40
+ return this.#symbols.has(exportSymbol);
41
+ }
42
+
43
+ hasLocalSymbol(local: Symbol): boolean {
44
+ return this.#locals.has(local);
45
+ }
46
+
47
+ exportSymbols(): Iterable<Symbol> {
48
+ return this.#symbols.keys();
49
+ }
50
+
51
+ set(
52
+ exportSymbol: Symbol,
53
+ local: Symbol,
54
+ loc: ?SourceLocation,
55
+ isWeak: ?boolean,
56
+ ): void {
57
+ this.#locals.add(local);
58
+ this.#symbols.set(exportSymbol, {
59
+ local,
60
+ loc,
61
+ meta: {},
62
+ isWeak: isWeak ?? false,
63
+ });
64
+ }
65
+
66
+ delete(exportSymbol: Symbol): void {
67
+ let existing = this.#symbols.get(exportSymbol);
68
+ if (!existing) return;
69
+ this.#locals.delete(existing.local);
70
+ this.#symbols.delete(exportSymbol);
71
+ }
72
+
73
+ /*:: @@iterator(): Iterator<[Symbol, DependencyAssetSymbol]> { return ({}: any); } */
74
+ // $FlowFixMe Flow can't do computed properties
75
+ [Symbol.iterator]() {
76
+ return this.#symbols.values();
77
+ }
78
+ }
79
+
80
+ // TODO
81
+ export class AssetSymbols
82
+ extends Array<[Symbol, AssetSymbol]>
83
+ implements ClassicAssetSymbols
84
+ {
85
+ isCleared: boolean;
86
+
87
+ // eslint-disable-next-line no-unused-vars
88
+ get(exportSymbol: Symbol): ?AssetSymbol {}
89
+
90
+ // eslint-disable-next-line no-unused-vars
91
+ hasExportSymbol(exportSymbol: Symbol): boolean {
92
+ throw new Error('AssetSymbols.hasExportSymbol');
93
+ }
94
+
95
+ // eslint-disable-next-line no-unused-vars
96
+ hasLocalSymbol(local: Symbol): boolean {
97
+ throw new Error('AssetSymbols.hasExportSymbol');
98
+ }
99
+
100
+ exportSymbols(): Iterable<Symbol> {
101
+ return [];
102
+ }
103
+ }
104
+
105
+ // TODO
106
+ export class MutableAssetSymbols
107
+ extends AssetSymbols
108
+ implements ClassicMutableAssetSymbols
109
+ {
110
+ ensure(): void {}
111
+ set(
112
+ // eslint-disable-next-line no-unused-vars
113
+ exportSymbol: Symbol,
114
+ // eslint-disable-next-line no-unused-vars
115
+ local: Symbol,
116
+ // eslint-disable-next-line no-unused-vars
117
+ loc: ?SourceLocation,
118
+ // eslint-disable-next-line no-unused-vars
119
+ meta?: ?Meta,
120
+ ): void {}
121
+
122
+ // eslint-disable-next-line no-unused-vars
123
+ delete(exportSymbol: Symbol): void {}
124
+ }
125
+
126
+ export type AssetSymbol = {|local: Symbol, loc: ?SourceLocation, meta?: ?Meta|};
127
+ export type DependencyAssetSymbol = {|
128
+ local: Symbol,
129
+ loc: ?SourceLocation,
130
+ meta?: ?Meta,
131
+ isWeak: boolean,
132
+ |};
@@ -0,0 +1,86 @@
1
+ // @flow
2
+
3
+ import type {
4
+ BundleBehavior,
5
+ DependencyPriority,
6
+ SpecifierType,
7
+ } from '@atlaspack/types';
8
+
9
+ /// BitFlags is used to map number/string types from napi types
10
+ export class BitFlags<K, V> {
11
+ #kv: {[key: K]: V};
12
+ #vk: {[key: V]: K};
13
+
14
+ constructor(source: {[key: K]: V}) {
15
+ this.#kv = source;
16
+ this.#vk = Object.fromEntries(
17
+ // $FlowFixMe
18
+ Object.entries(source).map(a => a.reverse()),
19
+ );
20
+ }
21
+
22
+ into(key: K): V {
23
+ const found = this.#kv[key];
24
+ if (found === undefined) {
25
+ // $FlowFixMe
26
+ throw new Error(`Invalid BundleBehavior(${key})`);
27
+ }
28
+ return found;
29
+ }
30
+
31
+ intoArray(keys: K[]): V[] {
32
+ return keys.map(key => this.into(key));
33
+ }
34
+
35
+ from(key: V): K {
36
+ const found = this.#vk[key];
37
+ if (found === undefined) {
38
+ // $FlowFixMe
39
+ throw new Error(`Invalid BundleBehavior(${key})`);
40
+ }
41
+ return found;
42
+ }
43
+
44
+ fromArray(keys: V[]): K[] {
45
+ return keys.map(key => this.from(key));
46
+ }
47
+ }
48
+
49
+ export const bundleBehaviorMap: BitFlags<BundleBehavior, number> = new BitFlags(
50
+ {
51
+ inline: 0,
52
+ isolated: 1,
53
+ },
54
+ );
55
+
56
+ export const dependencyPriorityMap: BitFlags<DependencyPriority, number> =
57
+ new BitFlags({
58
+ sync: 0,
59
+ parallel: 1,
60
+ lazy: 2,
61
+ conditional: 3,
62
+ });
63
+
64
+ export const packageConditionsMap: BitFlags<string, number> = new BitFlags({
65
+ import: 0,
66
+ require: 1,
67
+ module: 2,
68
+ node: 3,
69
+ browser: 4,
70
+ worker: 5,
71
+ worklet: 6,
72
+ electron: 7,
73
+ development: 8,
74
+ production: 9,
75
+ types: 10,
76
+ default: 11,
77
+ style: 12,
78
+ sass: 13,
79
+ });
80
+
81
+ export const specifierTypeMap: BitFlags<SpecifierType, number> = new BitFlags({
82
+ esm: 0,
83
+ commonjs: 1,
84
+ url: 2,
85
+ custom: 3,
86
+ });
@@ -0,0 +1,83 @@
1
+ // @flow
2
+
3
+ import type {Dependency as NapiDependency} from '@atlaspack/rust';
4
+ import type {
5
+ Dependency as ClassicDependency,
6
+ DependencySpecifier,
7
+ SpecifierType,
8
+ DependencyPriority,
9
+ BundleBehavior,
10
+ SourceLocation,
11
+ Environment as ClassicEnvironment,
12
+ Meta,
13
+ Target as ClassicTarget,
14
+ FilePath,
15
+ SemverRange,
16
+ MutableDependencySymbols as ClassicMutableDependencySymbols,
17
+ } from '@atlaspack/types';
18
+ import {Target} from './target';
19
+ import {MutableDependencySymbols} from './asset-symbols';
20
+ import {
21
+ bundleBehaviorMap,
22
+ specifierTypeMap,
23
+ dependencyPriorityMap,
24
+ packageConditionsMap,
25
+ } from './bitflags';
26
+
27
+ export class Dependency implements ClassicDependency {
28
+ env: ClassicEnvironment;
29
+ meta: Meta;
30
+ target: ?ClassicTarget;
31
+ symbols: ClassicMutableDependencySymbols;
32
+ specifier: DependencySpecifier;
33
+ specifierType: SpecifierType;
34
+ priority: DependencyPriority;
35
+ bundleBehavior: ?BundleBehavior;
36
+ needsStableName: boolean;
37
+ isOptional: boolean;
38
+ isEntry: boolean;
39
+ loc: ?SourceLocation;
40
+ packageConditions: ?Array<string>;
41
+ sourceAssetId: ?string;
42
+ sourcePath: ?FilePath;
43
+ sourceAssetType: ?string;
44
+ resolveFrom: ?FilePath;
45
+ range: ?SemverRange;
46
+ pipeline: ?string;
47
+
48
+ get id(): string {
49
+ throw new Error('Dependency.id');
50
+ }
51
+
52
+ constructor(inner: NapiDependency, env: ClassicEnvironment) {
53
+ this.env = env;
54
+ this.meta = inner.meta || {};
55
+ this.target = undefined;
56
+ if (inner.target) {
57
+ this.target = new Target(inner.target, this.env);
58
+ }
59
+ if (!inner.bundleBehavior) {
60
+ this.bundleBehavior = undefined;
61
+ } else {
62
+ this.bundleBehavior = bundleBehaviorMap.from(inner.bundleBehavior);
63
+ }
64
+ this.bundleBehavior = undefined;
65
+ this.symbols = new MutableDependencySymbols(inner.symbols || []);
66
+ this.specifier = inner.specifier;
67
+ this.specifierType = specifierTypeMap.from(inner.specifierType);
68
+ this.priority = dependencyPriorityMap.from(inner.priority);
69
+ this.needsStableName = inner.needsStableName;
70
+ this.isOptional = inner.isOptional;
71
+ this.isEntry = inner.isEntry;
72
+ this.loc = inner.loc;
73
+ this.packageConditions = packageConditionsMap.fromArray(
74
+ inner.packageConditions || [],
75
+ );
76
+ this.sourceAssetId = inner.sourceAssetId;
77
+ this.sourcePath = inner.sourcePath;
78
+ this.sourceAssetType = inner.sourceAssetType;
79
+ this.resolveFrom = inner.resolveFrom;
80
+ this.range = inner.range;
81
+ this.pipeline = inner.pipeline;
82
+ }
83
+ }
@@ -0,0 +1,92 @@
1
+ // @flow
2
+
3
+ import type {Environment as NapiEnvironment} from '@atlaspack/rust';
4
+ import type {
5
+ Environment as ClassicEnvironment,
6
+ EnvironmentContext,
7
+ Engines,
8
+ PackageName,
9
+ OutputFormat,
10
+ SourceType,
11
+ TargetSourceMapOptions,
12
+ SourceLocation,
13
+ VersionMap,
14
+ EnvironmentFeature,
15
+ } from '@atlaspack/types';
16
+
17
+ export class Environment implements ClassicEnvironment {
18
+ id: string;
19
+ includeNodeModules:
20
+ | boolean
21
+ | Array<PackageName>
22
+ | {[PackageName]: boolean, ...};
23
+ context: EnvironmentContext;
24
+ engines: Engines;
25
+ outputFormat: OutputFormat;
26
+ sourceType: SourceType;
27
+ isLibrary: boolean;
28
+ shouldOptimize: boolean;
29
+ shouldScopeHoist: boolean;
30
+ sourceMap: ?TargetSourceMapOptions;
31
+ loc: ?SourceLocation;
32
+
33
+ constructor(inner: NapiEnvironment) {
34
+ // TODO
35
+ this.id = '';
36
+ this.includeNodeModules = inner.includeNodeModules;
37
+ // $FlowFixMe
38
+ this.context = inner.context;
39
+ this.engines = inner.engines;
40
+ // $FlowFixMe
41
+ this.outputFormat = inner.outputFormat;
42
+ // $FlowFixMe
43
+ this.sourceType = inner.sourceType;
44
+ this.isLibrary = inner.isLibrary;
45
+ this.shouldOptimize = inner.shouldOptimize;
46
+ this.shouldScopeHoist = inner.shouldScopeHoist;
47
+ this.sourceMap = inner.sourceMap;
48
+ this.loc = inner.loc;
49
+ }
50
+
51
+ // TODO
52
+ isBrowser(): boolean {
53
+ return true;
54
+ }
55
+
56
+ // TODO
57
+ isNode(): boolean {
58
+ return false;
59
+ }
60
+
61
+ // TODO
62
+ isElectron(): boolean {
63
+ return false;
64
+ }
65
+
66
+ // TODO
67
+ isWorker(): boolean {
68
+ return false;
69
+ }
70
+
71
+ // TODO
72
+ isWorklet(): boolean {
73
+ return false;
74
+ }
75
+
76
+ // TODO
77
+ isIsolated(): boolean {
78
+ return false;
79
+ }
80
+
81
+ // TODO
82
+ // eslint-disable-next-line no-unused-vars
83
+ matchesEngines(minVersions: VersionMap, defaultValue?: boolean): boolean {
84
+ return true;
85
+ }
86
+
87
+ // TODO
88
+ // eslint-disable-next-line no-unused-vars
89
+ supports(feature: EnvironmentFeature, defaultValue?: boolean): boolean {
90
+ return true;
91
+ }
92
+ }
@@ -0,0 +1,7 @@
1
+ // @flow
2
+ export * from './asset-compat';
3
+ export * from './asset-symbols';
4
+ export * from './bitflags';
5
+ export * from './dependency';
6
+ export * from './environment';
7
+ export * from './target';
@@ -0,0 +1,27 @@
1
+ // @flow
2
+
3
+ import type {Target as NapiTarget} from '@atlaspack/rust';
4
+ import type {
5
+ Target as ClassicTarget,
6
+ FilePath,
7
+ Environment,
8
+ SourceLocation,
9
+ } from '@atlaspack/types';
10
+
11
+ export class Target implements ClassicTarget {
12
+ distEntry: ?FilePath;
13
+ distDir: FilePath;
14
+ env: Environment;
15
+ name: string;
16
+ publicUrl: string;
17
+ loc: ?SourceLocation;
18
+
19
+ constructor(inner: NapiTarget, env: Environment) {
20
+ this.distDir = inner.distDir;
21
+ this.distEntry = inner.distEntry;
22
+ this.name = inner.name;
23
+ this.publicUrl = inner.publicUrl;
24
+ this.loc = inner.loc;
25
+ this.env = env;
26
+ }
27
+ }
@@ -7,7 +7,6 @@ import type {
7
7
  Resolver,
8
8
  Transformer,
9
9
  PluginOptions,
10
- Dependency,
11
10
  FilePath,
12
11
  FileSystem,
13
12
  ConfigResultWithFilePath,
@@ -16,11 +15,10 @@ import type {
16
15
  import {workerData} from 'worker_threads';
17
16
  import * as module from 'module';
18
17
 
19
- import {AssetCompat} from './compat';
18
+ import {AssetCompat, Environment, Dependency} from './compat';
20
19
  import type {InnerAsset} from './compat';
21
20
  import {jsCallable} from '../jsCallable';
22
21
  import type {JsCallable} from '../jsCallable';
23
- import Environment from '../../public/Environment';
24
22
 
25
23
  const CONFIG = Symbol.for('parcel-plugin-config');
26
24
 
@@ -67,7 +65,13 @@ export class AtlaspackWorker {
67
65
  [RunResolverResolveOptions],
68
66
  Promise<RunResolverResolveResult>,
69
67
  > = jsCallable(
70
- async ({key, dependency, specifier, pipeline, projectRoot}) => {
68
+ async ({
69
+ key,
70
+ dependency: napiDependency,
71
+ specifier,
72
+ pipeline,
73
+ projectRoot,
74
+ }) => {
71
75
  const state = this.#resolvers.get(key);
72
76
  if (!state) {
73
77
  throw new Error(`Resolver not found: ${key}`);
@@ -79,6 +83,9 @@ export class AtlaspackWorker {
79
83
  state.packageManager = packageManager;
80
84
  }
81
85
 
86
+ const env = new Environment(napiDependency.env);
87
+ const dependency = new Dependency(napiDependency, env);
88
+
82
89
  const defaultOptions = {
83
90
  get logger() {
84
91
  // $FlowFixMe
@@ -132,10 +139,7 @@ export class AtlaspackWorker {
132
139
  isSource: true,
133
140
  searchPath: '',
134
141
  // $FlowFixMe This isn't correct to flow but is enough to satisfy the runtime checks
135
- env: new Environment(dependency.env, {
136
- projectRoot,
137
- hmrOptions: undefined,
138
- }),
142
+ env,
139
143
  invalidateOnFileChange(): void {},
140
144
  invalidateOnFileCreate(): void {},
141
145
  invalidateOnEnvChange(): void {},
@@ -280,7 +284,7 @@ type LoadPluginOptions = {|
280
284
 
281
285
  type RunResolverResolveOptions = {|
282
286
  key: string,
283
- dependency: Dependency,
287
+ dependency: napi.Dependency,
284
288
  specifier: FilePath,
285
289
  pipeline: ?string,
286
290
  projectRoot: string,