@atlaspack/core 2.12.1-dev.3443 → 2.12.1-dev.3460

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.
Files changed (94) hide show
  1. package/lib/AssetGraph.js +5 -1
  2. package/lib/Atlaspack.js +2 -2
  3. package/lib/Dependency.js +1 -1
  4. package/lib/PackagerRunner.js +45 -3
  5. package/lib/SymbolPropagation.js +25 -36
  6. package/lib/assetUtils.js +1 -1
  7. package/lib/atlaspack-v3/fs.js +31 -29
  8. package/lib/atlaspack-v3/index.js +2 -2
  9. package/lib/atlaspack-v3/jsCallable.js +9 -4
  10. package/lib/atlaspack-v3/worker/compat/asset-symbols.js +192 -0
  11. package/lib/atlaspack-v3/worker/compat/bitflags.js +84 -0
  12. package/lib/atlaspack-v3/worker/compat/dependency.js +44 -0
  13. package/lib/atlaspack-v3/worker/compat/environment.js +68 -0
  14. package/lib/atlaspack-v3/worker/compat/index.js +104 -0
  15. package/lib/atlaspack-v3/worker/compat/mutable-asset.js +144 -0
  16. package/lib/atlaspack-v3/worker/compat/plugin-config.js +58 -0
  17. package/lib/atlaspack-v3/worker/compat/plugin-logger.js +29 -0
  18. package/lib/atlaspack-v3/worker/compat/plugin-options.js +113 -0
  19. package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +12 -0
  20. package/lib/atlaspack-v3/worker/compat/target.js +17 -0
  21. package/lib/atlaspack-v3/worker/worker.js +162 -83
  22. package/lib/projectPath.js +12 -4
  23. package/lib/requests/ConfigRequest.js +1 -1
  24. package/lib/requests/WriteBundleRequest.js +15 -15
  25. package/package.json +23 -16
  26. package/src/AssetGraph.js +15 -13
  27. package/src/Atlaspack.js +5 -6
  28. package/src/AtlaspackConfig.js +11 -9
  29. package/src/AtlaspackConfig.schema.js +1 -1
  30. package/src/BundleGraph.js +83 -79
  31. package/src/CommittedAsset.js +1 -1
  32. package/src/Dependency.js +1 -1
  33. package/src/PackagerRunner.js +56 -8
  34. package/src/ReporterRunner.js +4 -4
  35. package/src/RequestTracker.js +18 -18
  36. package/src/SymbolPropagation.js +40 -52
  37. package/src/Transformation.js +12 -12
  38. package/src/UncommittedAsset.js +2 -2
  39. package/src/Validation.js +5 -5
  40. package/src/applyRuntimes.js +2 -2
  41. package/src/assetUtils.js +1 -1
  42. package/src/atlaspack-v3/AtlaspackV3.js +1 -1
  43. package/src/atlaspack-v3/fs.js +39 -25
  44. package/src/atlaspack-v3/index.js +1 -1
  45. package/src/atlaspack-v3/jsCallable.js +11 -10
  46. package/src/atlaspack-v3/worker/compat/asset-symbols.js +225 -0
  47. package/src/atlaspack-v3/worker/compat/bitflags.js +100 -0
  48. package/src/atlaspack-v3/worker/compat/dependency.js +83 -0
  49. package/src/atlaspack-v3/worker/compat/environment.js +92 -0
  50. package/src/atlaspack-v3/worker/compat/index.js +10 -0
  51. package/src/atlaspack-v3/worker/compat/mutable-asset.js +184 -0
  52. package/src/atlaspack-v3/worker/compat/plugin-config.js +94 -0
  53. package/src/atlaspack-v3/worker/compat/plugin-logger.js +47 -0
  54. package/src/atlaspack-v3/worker/compat/plugin-options.js +137 -0
  55. package/src/atlaspack-v3/worker/compat/plugin-tracer.js +11 -0
  56. package/src/atlaspack-v3/worker/compat/target.js +27 -0
  57. package/src/atlaspack-v3/worker/worker.js +218 -113
  58. package/src/dumpGraphToGraphViz.js +1 -1
  59. package/src/loadDotEnv.js +1 -1
  60. package/src/projectPath.js +12 -4
  61. package/src/public/Asset.js +1 -1
  62. package/src/public/Bundle.js +3 -3
  63. package/src/public/BundleGraph.js +20 -20
  64. package/src/public/Config.js +1 -1
  65. package/src/public/MutableBundleGraph.js +8 -8
  66. package/src/requests/AssetGraphRequest.js +10 -10
  67. package/src/requests/AssetGraphRequestRust.js +3 -3
  68. package/src/requests/AssetRequest.js +3 -3
  69. package/src/requests/AtlaspackConfigRequest.js +5 -3
  70. package/src/requests/BundleGraphRequest.js +6 -6
  71. package/src/requests/ConfigRequest.js +5 -5
  72. package/src/requests/DevDepRequest.js +7 -7
  73. package/src/requests/EntryRequest.js +2 -2
  74. package/src/requests/TargetRequest.js +9 -8
  75. package/src/requests/ValidationRequest.js +2 -2
  76. package/src/requests/WriteBundleRequest.js +26 -20
  77. package/src/requests/WriteBundlesRequest.js +6 -6
  78. package/src/requests/asset-graph-diff.js +4 -4
  79. package/src/resolveOptions.js +3 -3
  80. package/src/serializer.js +2 -2
  81. package/src/serializerCore.browser.js +3 -2
  82. package/src/serializerCore.js +2 -2
  83. package/src/utils.js +2 -2
  84. package/test/AtlaspackConfigRequest.test.js +1 -1
  85. package/test/BundleGraph.test.js +3 -3
  86. package/test/Dependency.test.js +28 -0
  87. package/test/PublicMutableBundleGraph.test.js +2 -2
  88. package/test/RequestTracker.test.js +7 -6
  89. package/test/SymbolPropagation.test.js +9 -9
  90. package/test/requests/ConfigRequest.test.js +3 -6
  91. package/test/utils.test.js +1 -1
  92. package/lib/atlaspack-v3/worker/compat.js +0 -57
  93. package/src/atlaspack-v3/worker/compat.js +0 -82
  94. package/test/requests/WriteBundleRequest.test.js +0 -132
@@ -1,6 +1,6 @@
1
1
  // @flow strict-local
2
2
 
3
- import type {FileSystem} from '@atlaspack/rust';
3
+ import type {FileSystem, JsCallable} from '@atlaspack/rust';
4
4
  import type {
5
5
  Encoding,
6
6
  FilePath,
@@ -9,33 +9,47 @@ import type {
9
9
 
10
10
  import {jsCallable} from './jsCallable';
11
11
 
12
- // Move to @atlaspack/utils or a dedicated v3 / migration package later
13
- export function toFileSystemV3(fs: ClassicFileSystem): FileSystem {
14
- return {
15
- canonicalize: jsCallable((path: FilePath) => fs.realpathSync(path)),
16
- createDirectory: jsCallable((path: FilePath) => fs.mkdirp(path)),
17
- cwd: jsCallable(() => fs.cwd()),
18
- readFile: jsCallable((path: string, encoding?: Encoding) => {
12
+ export class FileSystemV3 implements FileSystem {
13
+ #fs: ClassicFileSystem;
14
+
15
+ constructor(fs: ClassicFileSystem) {
16
+ this.#fs = fs;
17
+ }
18
+
19
+ canonicalize: JsCallable<[FilePath], FilePath> = jsCallable(
20
+ (path: FilePath) => this.#fs.realpathSync(path),
21
+ );
22
+
23
+ createDirectory: JsCallable<[FilePath], Promise<void>> = jsCallable(
24
+ (path: FilePath) => this.#fs.mkdirp(path),
25
+ );
26
+
27
+ cwd: JsCallable<[], FilePath> = jsCallable(() => this.#fs.cwd());
28
+
29
+ isFile: JsCallable<[FilePath], boolean> = (path: string) => {
30
+ try {
31
+ return this.#fs.statSync(path).isFile();
32
+ } catch {
33
+ return false;
34
+ }
35
+ };
36
+
37
+ isDir: JsCallable<[FilePath], boolean> = (path: string) => {
38
+ try {
39
+ return this.#fs.statSync(path).isDirectory();
40
+ } catch {
41
+ return false;
42
+ }
43
+ };
44
+
45
+ readFile: JsCallable<[FilePath, Encoding], string> = jsCallable(
46
+ (path: string, encoding?: Encoding) => {
19
47
  if (!encoding) {
20
48
  // $FlowFixMe
21
- return [...fs.readFileSync(path)];
49
+ return [...this.#fs.readFileSync(path)];
22
50
  } else {
23
- return fs.readFileSync(path, encoding);
24
- }
25
- }),
26
- isFile: (path: string) => {
27
- try {
28
- return fs.statSync(path).isFile();
29
- } catch {
30
- return false;
51
+ return this.#fs.readFileSync(path, encoding);
31
52
  }
32
53
  },
33
- isDir: (path: string) => {
34
- try {
35
- return fs.statSync(path).isDirectory();
36
- } catch {
37
- return false;
38
- }
39
- },
40
- };
54
+ );
41
55
  }
@@ -1,5 +1,5 @@
1
1
  // @flow
2
2
 
3
- export {toFileSystemV3} from './fs';
3
+ export {FileSystemV3} from './fs';
4
4
  export {AtlaspackV3} from './AtlaspackV3';
5
5
  export type * from './AtlaspackV3';
@@ -1,17 +1,18 @@
1
1
  // @flow strict-local
2
2
 
3
- export type JsCallable<Args: $ReadOnlyArray<mixed>, Return> = (
4
- ...Args
5
- ) => Return;
6
-
7
3
  export function jsCallable<Args: $ReadOnlyArray<mixed>, Return>(
8
- fn: (...Args) => Return,
9
- ): (...Args) => Return {
10
- return (...args: Args) => {
4
+ fn: (...Args) => Return | Promise<Return>,
5
+ ): (...Args) => Promise<Return> {
6
+ return async (...args: Args): Promise<Return> => {
11
7
  try {
12
- return fn(...args);
13
- } catch (err) {
14
- return err;
8
+ // $FlowFixMe "await" is needed to log the error from
9
+ // Promises and is safe to use on non-promises
10
+ return await fn(...args);
11
+ // $FlowFixMe
12
+ } catch (error) {
13
+ // eslint-disable-next-line no-console
14
+ console.error(error);
15
+ throw error;
15
16
  }
16
17
  };
17
18
  }
@@ -0,0 +1,225 @@
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[]) | null) {
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
+ export class AssetSymbols implements ClassicAssetSymbols {
81
+ #symbols: Map<Symbol, AssetSymbol>;
82
+ #locals: Set<Symbol>;
83
+
84
+ get isCleared(): boolean {
85
+ return this.#symbols.size === 0;
86
+ }
87
+
88
+ constructor(inner: ?(NapiSymbol[]) | null) {
89
+ this.#symbols = new Map();
90
+ this.#locals = new Set();
91
+ for (const {exported, local, loc} of inner || []) {
92
+ this.#set(exported, local, loc);
93
+ }
94
+ }
95
+
96
+ #set(exportSymbol: Symbol, local: Symbol, loc: ?SourceLocation): void {
97
+ this.#locals.add(local);
98
+ this.#symbols.set(exportSymbol, {
99
+ local,
100
+ loc,
101
+ meta: {},
102
+ });
103
+ }
104
+
105
+ get(exportSymbol: Symbol): ?AssetSymbol {
106
+ return this.#symbols.get(exportSymbol);
107
+ }
108
+
109
+ hasExportSymbol(exportSymbol: Symbol): boolean {
110
+ return this.#symbols.has(exportSymbol);
111
+ }
112
+
113
+ hasLocalSymbol(local: Symbol): boolean {
114
+ return this.#locals.has(local);
115
+ }
116
+
117
+ exportSymbols(): Iterable<Symbol> {
118
+ return this.#symbols.keys();
119
+ }
120
+
121
+ intoNapi(): NapiSymbol[] {
122
+ return [];
123
+ }
124
+
125
+ /*:: @@iterator(): Iterator<[Symbol, AssetSymbol]> { return ({}: any); } */
126
+ // $FlowFixMe Flow can't do computed properties
127
+ [Symbol.iterator]() {
128
+ return this.#symbols.values();
129
+ }
130
+ }
131
+
132
+ export class MutableAssetSymbols implements ClassicMutableAssetSymbols {
133
+ #symbols: Map<Symbol, AssetSymbol>;
134
+ #locals: Set<Symbol>;
135
+
136
+ get isCleared(): boolean {
137
+ return this.#symbols.size === 0;
138
+ }
139
+
140
+ constructor(inner: ?(NapiSymbol[]) | null) {
141
+ this.#symbols = new Map();
142
+ this.#locals = new Set();
143
+ for (const {exported, local, loc} of inner || []) {
144
+ this.set(exported, local, loc);
145
+ }
146
+ }
147
+
148
+ intoNapi(): NapiSymbol[] {
149
+ const results: NapiSymbol[] = [];
150
+ for (const [exportSymbol, {local, loc}] of this.#symbols.entries()) {
151
+ results.push({
152
+ exported: exportSymbol,
153
+ local,
154
+ loc: loc
155
+ ? {
156
+ filePath: loc.filePath,
157
+ start: {
158
+ line: loc.start.line,
159
+ column: loc.start.column,
160
+ },
161
+ end: {
162
+ line: loc.end.line,
163
+ column: loc.end.column,
164
+ },
165
+ }
166
+ : undefined,
167
+ // TODO
168
+ isWeak: false,
169
+ isEsmExport: false,
170
+ selfReferenced: false,
171
+ });
172
+ }
173
+ return results;
174
+ }
175
+
176
+ ensure(): void {
177
+ throw new Error('MutableAssetSymbols.ensure()');
178
+ }
179
+
180
+ set(exportSymbol: Symbol, local: Symbol, loc: ?SourceLocation): void {
181
+ this.#locals.add(local);
182
+ this.#symbols.set(exportSymbol, {
183
+ local,
184
+ loc,
185
+ meta: {},
186
+ });
187
+ }
188
+
189
+ get(exportSymbol: Symbol): ?AssetSymbol {
190
+ return this.#symbols.get(exportSymbol);
191
+ }
192
+
193
+ hasExportSymbol(exportSymbol: Symbol): boolean {
194
+ return this.#symbols.has(exportSymbol);
195
+ }
196
+
197
+ hasLocalSymbol(local: Symbol): boolean {
198
+ return this.#locals.has(local);
199
+ }
200
+
201
+ exportSymbols(): Iterable<Symbol> {
202
+ return this.#symbols.keys();
203
+ }
204
+
205
+ delete(exportSymbol: Symbol): void {
206
+ let existing = this.#symbols.get(exportSymbol);
207
+ if (!existing) return;
208
+ this.#locals.delete(existing.local);
209
+ this.#symbols.delete(exportSymbol);
210
+ }
211
+
212
+ /*:: @@iterator(): Iterator<[Symbol, AssetSymbol]> { return ({}: any); } */
213
+ // $FlowFixMe Flow can't do computed properties
214
+ [Symbol.iterator]() {
215
+ return this.#symbols.values();
216
+ }
217
+ }
218
+
219
+ export type AssetSymbol = {|local: Symbol, loc: ?SourceLocation, meta?: ?Meta|};
220
+ export type DependencyAssetSymbol = {|
221
+ local: Symbol,
222
+ loc: ?SourceLocation,
223
+ meta?: ?Meta,
224
+ isWeak: boolean,
225
+ |};
@@ -0,0 +1,100 @@
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
+ intoNullable(key: ?K): ?V {
32
+ if (key === undefined || key === null) {
33
+ return undefined;
34
+ }
35
+ return this.into(key);
36
+ }
37
+
38
+ intoArray(keys: K[]): V[] {
39
+ return keys.map((key) => this.into(key));
40
+ }
41
+
42
+ from(key: V): K {
43
+ const found = this.#vk[key];
44
+ if (found === undefined) {
45
+ // $FlowFixMe
46
+ throw new Error(`Invalid BundleBehavior(${key})`);
47
+ }
48
+ return found;
49
+ }
50
+
51
+ fromNullable(key: ?V): ?K {
52
+ if (key === undefined || key === null) {
53
+ return undefined;
54
+ }
55
+ return this.from(key);
56
+ }
57
+
58
+ fromArray(keys: V[]): K[] {
59
+ return keys.map((key) => this.from(key));
60
+ }
61
+ }
62
+
63
+ export const bundleBehaviorMap: BitFlags<BundleBehavior, number> = new BitFlags(
64
+ {
65
+ inline: 0,
66
+ isolated: 1,
67
+ },
68
+ );
69
+
70
+ export const dependencyPriorityMap: BitFlags<DependencyPriority, number> =
71
+ new BitFlags({
72
+ sync: 0,
73
+ parallel: 1,
74
+ lazy: 2,
75
+ conditional: 3,
76
+ });
77
+
78
+ export const packageConditionsMap: BitFlags<string, number> = new BitFlags({
79
+ import: 0,
80
+ require: 1,
81
+ module: 2,
82
+ node: 3,
83
+ browser: 4,
84
+ worker: 5,
85
+ worklet: 6,
86
+ electron: 7,
87
+ development: 8,
88
+ production: 9,
89
+ types: 10,
90
+ default: 11,
91
+ style: 12,
92
+ sass: 13,
93
+ });
94
+
95
+ export const specifierTypeMap: BitFlags<SpecifierType, number> = new BitFlags({
96
+ esm: 0,
97
+ commonjs: 1,
98
+ url: 2,
99
+ custom: 3,
100
+ });
@@ -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,10 @@
1
+ // @flow
2
+ export * from './bitflags';
3
+ export * from './dependency';
4
+ export * from './environment';
5
+ export * from './target';
6
+ export * from './plugin-config';
7
+ export * from './plugin-tracer';
8
+ export * from './plugin-logger';
9
+ export * from './plugin-options';
10
+ export * from './mutable-asset';