@atlaspack/core 2.12.1-canary.3472 → 2.12.1-canary.3479

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,55 +4,75 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.PluginConfig = void 0;
7
+ var _Config = _interopRequireDefault(require("../../../public/Config"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
9
  class PluginConfig {
10
+ #projectRoot;
11
+ #inner;
8
12
  constructor({
9
13
  env,
10
14
  isSource,
11
- searchPath
15
+ searchPath,
16
+ projectRoot,
17
+ fs,
18
+ packageManager
12
19
  }) {
13
20
  this.env = env;
14
21
  this.isSource = isSource;
15
22
  this.searchPath = searchPath;
23
+ this.#inner = new _Config.default(
24
+ // $FlowFixMe
25
+ {
26
+ invalidateOnConfigKeyChange: [],
27
+ invalidateOnFileCreate: [],
28
+ invalidateOnFileChange: new Set(),
29
+ devDeps: [],
30
+ // $FlowFixMe
31
+ searchPath: searchPath.replace(projectRoot + '/', '')
32
+ },
33
+ // $FlowFixMe
34
+ {
35
+ projectRoot,
36
+ inputFS: fs,
37
+ outputFS: fs,
38
+ packageManager
39
+ });
16
40
  }
17
41
 
18
42
  // eslint-disable-next-line no-unused-vars
19
- invalidateOnFileChange() {
20
- throw new Error('PluginOptions.invalidateOnFileChange');
21
- }
43
+ invalidateOnFileChange() {}
22
44
 
23
45
  // eslint-disable-next-line no-unused-vars
24
- invalidateOnFileCreate() {
25
- throw new Error('PluginOptions.invalidateOnFileCreate');
26
- }
46
+ invalidateOnFileCreate() {}
27
47
 
28
48
  // eslint-disable-next-line no-unused-vars
29
- invalidateOnEnvChange() {
30
- throw new Error('PluginOptions.invalidateOnEnvChange');
31
- }
32
- invalidateOnStartup() {
33
- throw new Error('PluginOptions.invalidateOnStartup');
34
- }
35
- invalidateOnBuild() {
36
- throw new Error('PluginOptions.invalidateOnBuild');
37
- }
49
+ invalidateOnEnvChange() {}
50
+ invalidateOnStartup() {}
51
+ invalidateOnBuild() {}
38
52
 
39
53
  // eslint-disable-next-line no-unused-vars
40
- addDevDependency() {
41
- throw new Error('PluginOptions.addDevDependency');
42
- }
54
+ addDevDependency() {}
43
55
 
44
56
  // eslint-disable-next-line no-unused-vars
45
- setCacheKey() {
46
- throw new Error('PluginOptions.setCacheKey');
47
- }
48
- getConfig() {
49
- throw new Error('PluginOptions.getConfig');
57
+ setCacheKey() {}
58
+ getConfig(
59
+ // eslint-disable-next-line no-unused-vars
60
+ filePaths,
61
+ // eslint-disable-next-line no-unused-vars
62
+ options) {
63
+ return this.#inner.getConfig(filePaths, options);
50
64
  }
51
- getConfigFrom() {
52
- throw new Error('PluginOptions.getConfigFrom');
65
+ getConfigFrom(
66
+ // eslint-disable-next-line no-unused-vars
67
+ searchPath,
68
+ // eslint-disable-next-line no-unused-vars
69
+ filePaths,
70
+ // eslint-disable-next-line no-unused-vars
71
+ options) {
72
+ return this.#inner.getConfigFrom(searchPath, filePaths, options);
53
73
  }
54
74
  getPackage() {
55
- throw new Error('PluginOptions.getPackage');
75
+ return this.#inner.getPackage();
56
76
  }
57
77
  }
58
78
  exports.PluginConfig = PluginConfig;
@@ -96,7 +96,7 @@ class AtlaspackWorker {
96
96
  dependency: napiDependency,
97
97
  specifier,
98
98
  pipeline,
99
- options
99
+ pluginOptions
100
100
  }) => {
101
101
  const state = this.#resolvers.get(key);
102
102
  if (!state) {
@@ -104,7 +104,7 @@ class AtlaspackWorker {
104
104
  }
105
105
  let packageManager = state.packageManager;
106
106
  if (!packageManager) {
107
- packageManager = new (_packageManager().NodePackageManager)(this.#fs, options.projectRoot);
107
+ packageManager = new (_packageManager().NodePackageManager)(this.#fs, pluginOptions.projectRoot);
108
108
  state.packageManager = packageManager;
109
109
  }
110
110
  const env = new _compat.Environment(napiDependency.env);
@@ -113,7 +113,7 @@ class AtlaspackWorker {
113
113
  logger: new _compat.PluginLogger(),
114
114
  tracer: new _compat.PluginTracer(),
115
115
  options: new _compat.PluginOptions({
116
- ...options,
116
+ ...pluginOptions,
117
117
  packageManager,
118
118
  shouldAutoInstall: false,
119
119
  inputFS: this.#fs,
@@ -126,7 +126,10 @@ class AtlaspackWorker {
126
126
  config: new _compat.PluginConfig({
127
127
  env,
128
128
  isSource: true,
129
- searchPath: ''
129
+ searchPath: specifier,
130
+ projectRoot: pluginOptions.projectRoot,
131
+ fs: this.#fs,
132
+ packageManager
130
133
  }),
131
134
  ...defaultOptions
132
135
  }));
@@ -178,6 +181,9 @@ class AtlaspackWorker {
178
181
  state.packageManager = packageManager;
179
182
  }
180
183
  const transformer = state.transformer;
184
+ const resolveFunc = (from, to) => Promise.resolve(require.resolve(to, {
185
+ paths: [from]
186
+ }));
181
187
  const env = new _compat.Environment(napiEnv);
182
188
  const mutableAsset = new _compat.MutableAsset(innerAsset, this.#fs, env);
183
189
  const defaultOptions = {
@@ -195,7 +201,10 @@ class AtlaspackWorker {
195
201
  config: new _compat.PluginConfig({
196
202
  env,
197
203
  isSource: true,
198
- searchPath: ''
204
+ searchPath: innerAsset.filePath.replace(options.projectRoot + '/', ''),
205
+ projectRoot: options.projectRoot,
206
+ fs: this.#fs,
207
+ packageManager
199
208
  }),
200
209
  ...defaultOptions
201
210
  }));
@@ -203,9 +212,7 @@ class AtlaspackWorker {
203
212
  const ast = await transformer.parse({
204
213
  asset: mutableAsset,
205
214
  config,
206
- get resolve() {
207
- throw new Error('Transformer.parse.resolve()');
208
- },
215
+ resolve: resolveFunc,
209
216
  ...defaultOptions
210
217
  });
211
218
  if (ast) {
@@ -215,9 +222,7 @@ class AtlaspackWorker {
215
222
  const result = await state.transformer.transform({
216
223
  asset: mutableAsset,
217
224
  config,
218
- get resolve() {
219
- throw new Error('Transformer.transform.resolve()');
220
- },
225
+ resolve: resolveFunc,
221
226
  ...defaultOptions
222
227
  });
223
228
  if (transformer.generate) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/core",
3
- "version": "2.12.1-canary.3472+8209dde07",
3
+ "version": "2.12.1-canary.3479+fee04114b",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -20,21 +20,21 @@
20
20
  "check-ts": "tsc --noEmit index.d.ts"
21
21
  },
22
22
  "dependencies": {
23
- "@atlaspack/build-cache": "2.12.1-canary.3472+8209dde07",
24
- "@atlaspack/cache": "2.12.1-canary.3472+8209dde07",
25
- "@atlaspack/diagnostic": "2.12.1-canary.3472+8209dde07",
26
- "@atlaspack/events": "2.12.1-canary.3472+8209dde07",
27
- "@atlaspack/feature-flags": "2.12.1-canary.3472+8209dde07",
28
- "@atlaspack/fs": "2.12.1-canary.3472+8209dde07",
29
- "@atlaspack/graph": "3.2.1-canary.3472+8209dde07",
30
- "@atlaspack/logger": "2.12.1-canary.3472+8209dde07",
31
- "@atlaspack/package-manager": "2.12.1-canary.3472+8209dde07",
32
- "@atlaspack/plugin": "2.12.1-canary.3472+8209dde07",
33
- "@atlaspack/profiler": "2.12.1-canary.3472+8209dde07",
34
- "@atlaspack/rust": "2.12.1-canary.3472+8209dde07",
35
- "@atlaspack/types": "2.12.1-canary.3472+8209dde07",
36
- "@atlaspack/utils": "2.12.1-canary.3472+8209dde07",
37
- "@atlaspack/workers": "2.12.1-canary.3472+8209dde07",
23
+ "@atlaspack/build-cache": "2.12.1-canary.3479+fee04114b",
24
+ "@atlaspack/cache": "2.12.1-canary.3479+fee04114b",
25
+ "@atlaspack/diagnostic": "2.12.1-canary.3479+fee04114b",
26
+ "@atlaspack/events": "2.12.1-canary.3479+fee04114b",
27
+ "@atlaspack/feature-flags": "2.12.1-canary.3479+fee04114b",
28
+ "@atlaspack/fs": "2.12.1-canary.3479+fee04114b",
29
+ "@atlaspack/graph": "3.2.1-canary.3479+fee04114b",
30
+ "@atlaspack/logger": "2.12.1-canary.3479+fee04114b",
31
+ "@atlaspack/package-manager": "2.12.1-canary.3479+fee04114b",
32
+ "@atlaspack/plugin": "2.12.1-canary.3479+fee04114b",
33
+ "@atlaspack/profiler": "2.12.1-canary.3479+fee04114b",
34
+ "@atlaspack/rust": "2.12.1-canary.3479+fee04114b",
35
+ "@atlaspack/types": "2.12.1-canary.3479+fee04114b",
36
+ "@atlaspack/utils": "2.12.1-canary.3479+fee04114b",
37
+ "@atlaspack/workers": "2.12.1-canary.3479+fee04114b",
38
38
  "@mischnic/json-sourcemap": "^0.1.0",
39
39
  "@parcel/source-map": "^2.1.1",
40
40
  "base-x": "^3.0.8",
@@ -65,5 +65,5 @@
65
65
  "browser": {
66
66
  "./src/serializerCore.js": "./src/serializerCore.browser.js"
67
67
  },
68
- "gitHead": "8209dde072b0d4726f70bcb319099a496c2651a1"
68
+ "gitHead": "fee04114bacb1df702084385bb7e995b3344b2da"
69
69
  }
@@ -8,57 +8,78 @@ import type {
8
8
  FileCreateInvalidation,
9
9
  ConfigResultWithFilePath,
10
10
  PackageJSON,
11
+ PackageManager as IPackageManager,
11
12
  } from '@atlaspack/types';
12
13
 
14
+ import type {FileSystem as IFileSystem} from '@atlaspack/fs';
15
+ import ClassicPublicConfig from '../../../public/Config';
16
+
13
17
  export type PluginConfigOptions = {|
14
18
  isSource: boolean,
15
19
  searchPath: FilePath,
20
+ projectRoot: FilePath,
16
21
  env: Environment,
22
+ fs: IFileSystem,
23
+ packageManager: IPackageManager,
17
24
  |};
18
25
 
19
26
  export class PluginConfig implements IPluginConfig {
20
27
  isSource: boolean;
21
28
  searchPath: FilePath;
29
+ #projectRoot: FilePath;
22
30
  env: Environment;
31
+ #inner: ClassicPublicConfig;
23
32
 
24
- constructor({env, isSource, searchPath}: PluginConfigOptions) {
33
+ constructor({
34
+ env,
35
+ isSource,
36
+ searchPath,
37
+ projectRoot,
38
+ fs,
39
+ packageManager,
40
+ }: PluginConfigOptions) {
25
41
  this.env = env;
26
42
  this.isSource = isSource;
27
43
  this.searchPath = searchPath;
44
+
45
+ this.#inner = new ClassicPublicConfig(
46
+ // $FlowFixMe
47
+ {
48
+ invalidateOnConfigKeyChange: [],
49
+ invalidateOnFileCreate: [],
50
+ invalidateOnFileChange: new Set(),
51
+ devDeps: [],
52
+ // $FlowFixMe
53
+ searchPath: searchPath.replace(projectRoot + '/', ''),
54
+ },
55
+ // $FlowFixMe
56
+ {
57
+ projectRoot,
58
+ inputFS: fs,
59
+ outputFS: fs,
60
+ packageManager,
61
+ },
62
+ );
28
63
  }
29
64
 
30
65
  // eslint-disable-next-line no-unused-vars
31
- invalidateOnFileChange(filePath: FilePath): void {
32
- throw new Error('PluginOptions.invalidateOnFileChange');
33
- }
66
+ invalidateOnFileChange(filePath: FilePath): void {}
34
67
 
35
68
  // eslint-disable-next-line no-unused-vars
36
- invalidateOnFileCreate(invalidations: FileCreateInvalidation): void {
37
- throw new Error('PluginOptions.invalidateOnFileCreate');
38
- }
69
+ invalidateOnFileCreate(invalidations: FileCreateInvalidation): void {}
39
70
 
40
71
  // eslint-disable-next-line no-unused-vars
41
- invalidateOnEnvChange(invalidation: string): void {
42
- throw new Error('PluginOptions.invalidateOnEnvChange');
43
- }
72
+ invalidateOnEnvChange(invalidation: string): void {}
44
73
 
45
- invalidateOnStartup(): void {
46
- throw new Error('PluginOptions.invalidateOnStartup');
47
- }
74
+ invalidateOnStartup(): void {}
48
75
 
49
- invalidateOnBuild(): void {
50
- throw new Error('PluginOptions.invalidateOnBuild');
51
- }
76
+ invalidateOnBuild(): void {}
52
77
 
53
78
  // eslint-disable-next-line no-unused-vars
54
- addDevDependency(options: DevDepOptions): void {
55
- throw new Error('PluginOptions.addDevDependency');
56
- }
79
+ addDevDependency(options: DevDepOptions): void {}
57
80
 
58
81
  // eslint-disable-next-line no-unused-vars
59
- setCacheKey(key: string): void {
60
- throw new Error('PluginOptions.setCacheKey');
61
- }
82
+ setCacheKey(key: string): void {}
62
83
 
63
84
  getConfig<T>(
64
85
  // eslint-disable-next-line no-unused-vars
@@ -70,7 +91,7 @@ export class PluginConfig implements IPluginConfig {
70
91
  exclude?: boolean,
71
92
  |},
72
93
  ): Promise<?ConfigResultWithFilePath<T>> {
73
- throw new Error('PluginOptions.getConfig');
94
+ return this.#inner.getConfig(filePaths, options);
74
95
  }
75
96
 
76
97
  getConfigFrom<T>(
@@ -85,10 +106,10 @@ export class PluginConfig implements IPluginConfig {
85
106
  exclude?: boolean,
86
107
  |},
87
108
  ): Promise<?ConfigResultWithFilePath<T>> {
88
- throw new Error('PluginOptions.getConfigFrom');
109
+ return this.#inner.getConfigFrom(searchPath, filePaths, options);
89
110
  }
90
111
 
91
112
  getPackage(): Promise<?PackageJSON> {
92
- throw new Error('PluginOptions.getPackage');
113
+ return this.#inner.getPackage();
93
114
  }
94
115
  }
@@ -76,7 +76,13 @@ export class AtlaspackWorker {
76
76
  [RunResolverResolveOptions],
77
77
  Promise<RunResolverResolveResult>,
78
78
  > = jsCallable(
79
- async ({key, dependency: napiDependency, specifier, pipeline, options}) => {
79
+ async ({
80
+ key,
81
+ dependency: napiDependency,
82
+ specifier,
83
+ pipeline,
84
+ pluginOptions,
85
+ }) => {
80
86
  const state = this.#resolvers.get(key);
81
87
  if (!state) {
82
88
  throw new Error(`Resolver not found: ${key}`);
@@ -84,7 +90,10 @@ export class AtlaspackWorker {
84
90
 
85
91
  let packageManager = state.packageManager;
86
92
  if (!packageManager) {
87
- packageManager = new NodePackageManager(this.#fs, options.projectRoot);
93
+ packageManager = new NodePackageManager(
94
+ this.#fs,
95
+ pluginOptions.projectRoot,
96
+ );
88
97
  state.packageManager = packageManager;
89
98
  }
90
99
 
@@ -95,7 +104,7 @@ export class AtlaspackWorker {
95
104
  logger: new PluginLogger(),
96
105
  tracer: new PluginTracer(),
97
106
  options: new PluginOptions({
98
- ...options,
107
+ ...pluginOptions,
99
108
  packageManager,
100
109
  shouldAutoInstall: false,
101
110
  inputFS: this.#fs,
@@ -108,7 +117,10 @@ export class AtlaspackWorker {
108
117
  config: new PluginConfig({
109
118
  env,
110
119
  isSource: true,
111
- searchPath: '',
120
+ searchPath: specifier,
121
+ projectRoot: pluginOptions.projectRoot,
122
+ fs: this.#fs,
123
+ packageManager,
112
124
  }),
113
125
  ...defaultOptions,
114
126
  });
@@ -162,6 +174,8 @@ export class AtlaspackWorker {
162
174
  }
163
175
 
164
176
  const transformer: Transformer<any> = state.transformer;
177
+ const resolveFunc = (from: string, to: string): Promise<any> =>
178
+ Promise.resolve(require.resolve(to, {paths: [from]}));
165
179
  const env = new Environment(napiEnv);
166
180
  const mutableAsset = new MutableAsset(innerAsset, this.#fs, env);
167
181
  const defaultOptions = {
@@ -180,7 +194,10 @@ export class AtlaspackWorker {
180
194
  config: new PluginConfig({
181
195
  env,
182
196
  isSource: true,
183
- searchPath: '',
197
+ searchPath: innerAsset.filePath.replace(options.projectRoot + '/', ''),
198
+ projectRoot: options.projectRoot,
199
+ fs: this.#fs,
200
+ packageManager,
184
201
  }),
185
202
  ...defaultOptions,
186
203
  });
@@ -189,9 +206,7 @@ export class AtlaspackWorker {
189
206
  const ast = await transformer.parse({
190
207
  asset: mutableAsset,
191
208
  config,
192
- get resolve() {
193
- throw new Error('Transformer.parse.resolve()');
194
- },
209
+ resolve: resolveFunc,
195
210
  ...defaultOptions,
196
211
  });
197
212
  if (ast) {
@@ -202,9 +217,7 @@ export class AtlaspackWorker {
202
217
  const result = await state.transformer.transform({
203
218
  asset: mutableAsset,
204
219
  config,
205
- get resolve() {
206
- throw new Error('Transformer.transform.resolve()');
207
- },
220
+ resolve: resolveFunc,
208
221
  ...defaultOptions,
209
222
  });
210
223
 
@@ -289,7 +302,7 @@ type RunResolverResolveOptions = {|
289
302
  dependency: napi.Dependency,
290
303
  specifier: FilePath,
291
304
  pipeline: ?string,
292
- options: RpcPluginOptions,
305
+ pluginOptions: RpcPluginOptions,
293
306
  |};
294
307
 
295
308
  type RunResolverResolveResult = {|