@atlaspack/package-manager 2.14.28 → 2.14.29

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @atlaspack/package-manager
2
2
 
3
+ ## 2.14.29
4
+
5
+ ### Patch Changes
6
+
7
+ - [#764](https://github.com/atlassian-labs/atlaspack/pull/764) [`58ddd5d`](https://github.com/atlassian-labs/atlaspack/commit/58ddd5d79adde2ac5dc4c60ca575e4705a91e592) Thanks [@mattcompiles](https://github.com/mattcompiles)! - Fix using Atlaspack linked with source files
8
+
9
+ - Updated dependencies [[`53dd47b`](https://github.com/atlassian-labs/atlaspack/commit/53dd47bd6d23cd47f87297347f03a609ab38a03d)]:
10
+ - @atlaspack/node-resolver-core@3.7.0
11
+ - @atlaspack/fs@2.15.24
12
+ - @atlaspack/utils@2.19.1
13
+ - @atlaspack/logger@2.14.21
14
+ - @atlaspack/types@2.15.19
15
+ - @atlaspack/workers@2.14.29
16
+
3
17
  ## 2.14.28
4
18
 
5
19
  ### Patch Changes
@@ -110,6 +110,7 @@ if (process.env.ATLASPACK_REGISTER_USE_SRC === 'true') {
110
110
  ENTRIES |= SOURCE;
111
111
  }
112
112
  const NODE_MODULES = `${_path().default.sep}node_modules${_path().default.sep}`;
113
+ const compileExtensions = new Set(['.ts', '.tsx', '.mts', '.cts']);
113
114
 
114
115
  // There can be more than one instance of NodePackageManager, but node has only a single module cache.
115
116
  // Therefore, the resolution cache and the map of parent to child modules should also be global.
@@ -130,6 +131,9 @@ class NodePackageManager {
130
131
  this.projectRoot = projectRoot;
131
132
  this.installer = installer;
132
133
 
134
+ // If using src then assume we're linked and find the link root dir
135
+ this.atlaspackLinkRoot = process.env.ATLASPACK_REGISTER_USE_SRC === 'true' ? _path().default.resolve(__dirname, '../../../..') : null;
136
+
133
137
  // @ts-expect-error TS2339
134
138
  this.currentExtensions = Object.keys(_module().default._extensions).map(e => e.substring(1));
135
139
  }
@@ -245,32 +249,52 @@ class NodePackageManager {
245
249
  _fs2().default.statSync = filename => {
246
250
  return this.fs.statSync(filename);
247
251
  };
248
- if (!filePath.includes(NODE_MODULES)) {
249
- let extname = _path().default.extname(filePath);
250
- if ((extname === '.ts' || extname === '.tsx' || extname === '.mts' || extname === '.cts') &&
252
+ let extname = _path().default.extname(filePath);
253
+ function shouldCompile(atlaspackLinkRoot) {
254
+ if (filePath.includes(NODE_MODULES)) {
255
+ // Don't compile node_modules
256
+ return false;
257
+ }
258
+ if (!compileExtensions.has(extname)) {
259
+ // Ignore non-TS files
260
+ return false;
261
+ }
262
+ if (atlaspackLinkRoot != null) {
263
+ // If we're linked, only compile files outside the linked atlaspack
264
+ // as those are handled by @atlaspack/babel-register
265
+ return !filePath.startsWith(atlaspackLinkRoot);
266
+ }
267
+
251
268
  // @ts-expect-error TS2339
252
- !_module().default._extensions[extname]) {
253
- // @ts-expect-error TS2339
254
- let compile = m._compile;
255
- // @ts-expect-error TS2339
256
- m._compile = (code, filename) => {
257
- let out = (0, _core().transformSync)(code, {
258
- filename,
259
- module: {
260
- type: 'commonjs'
269
+ // Lastly make sure there's no existing loader for this extension
270
+ return !_module().default._extensions[extname];
271
+ }
272
+ if (shouldCompile(this.atlaspackLinkRoot)) {
273
+ // @ts-expect-error TS2339
274
+ let compile = m._compile;
275
+ // @ts-expect-error TS2339
276
+ m._compile = (code, filename) => {
277
+ let out = (0, _core().transformSync)(code, {
278
+ filename,
279
+ module: {
280
+ type: 'commonjs'
281
+ },
282
+ env: {
283
+ targets: {
284
+ node: '18'
261
285
  }
262
- });
263
- compile.call(m, out.code, filename);
264
- };
286
+ }
287
+ });
288
+ compile.call(m, out.code, filename);
289
+ };
265
290
 
291
+ // @ts-expect-error TS2339
292
+ _module().default._extensions[extname] = (m, filename) => {
266
293
  // @ts-expect-error TS2339
267
- _module().default._extensions[extname] = (m, filename) => {
268
- // @ts-expect-error TS2339
269
- delete _module().default._extensions[extname];
270
- // @ts-expect-error TS2339
271
- _module().default._extensions['.js'](m, filename);
272
- };
273
- }
294
+ delete _module().default._extensions[extname];
295
+ // @ts-expect-error TS2339
296
+ _module().default._extensions['.js'](m, filename);
297
+ };
274
298
  }
275
299
  try {
276
300
  // @ts-expect-error TS2339
@@ -7,6 +7,7 @@ export declare class NodePackageManager implements PackageManager {
7
7
  installer: PackageInstaller | null | undefined;
8
8
  resolver: ResolverBase;
9
9
  currentExtensions: Array<string>;
10
+ atlaspackLinkRoot: string | null;
10
11
  constructor(fs: FileSystem, projectRoot: FilePath, installer?: PackageInstaller | null);
11
12
  _createResolver(): ResolverBase;
12
13
  static deserialize(opts: any): NodePackageManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/package-manager",
3
- "version": "2.14.28",
3
+ "version": "2.14.29",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "publishConfig": {
@@ -41,12 +41,12 @@
41
41
  "dependencies": {
42
42
  "@atlaspack/build-cache": "2.13.5",
43
43
  "@atlaspack/diagnostic": "2.14.3",
44
- "@atlaspack/fs": "2.15.23",
45
- "@atlaspack/logger": "2.14.20",
46
- "@atlaspack/node-resolver-core": "3.6.4",
47
- "@atlaspack/types": "2.15.18",
48
- "@atlaspack/utils": "2.19.0",
49
- "@atlaspack/workers": "2.14.28",
44
+ "@atlaspack/fs": "2.15.24",
45
+ "@atlaspack/logger": "2.14.21",
46
+ "@atlaspack/node-resolver-core": "3.7.0",
47
+ "@atlaspack/types": "2.15.19",
48
+ "@atlaspack/utils": "2.19.1",
49
+ "@atlaspack/workers": "2.14.29",
50
50
  "@swc/core": "^1.10.0",
51
51
  "semver": "^7.5.2",
52
52
  "command-exists": "^1.2.6",
@@ -46,6 +46,7 @@ if (process.env.ATLASPACK_REGISTER_USE_SRC === 'true') {
46
46
  }
47
47
 
48
48
  const NODE_MODULES = `${path.sep}node_modules${path.sep}`;
49
+ const compileExtensions = new Set(['.ts', '.tsx', '.mts', '.cts']);
49
50
 
50
51
  // There can be more than one instance of NodePackageManager, but node has only a single module cache.
51
52
  // Therefore, the resolution cache and the map of parent to child modules should also be global.
@@ -65,6 +66,7 @@ export class NodePackageManager implements PackageManager {
65
66
  // @ts-expect-error TS2749
66
67
  resolver: ResolverBase;
67
68
  currentExtensions: Array<string>;
69
+ atlaspackLinkRoot: string | null;
68
70
 
69
71
  constructor(
70
72
  fs: FileSystem,
@@ -75,6 +77,12 @@ export class NodePackageManager implements PackageManager {
75
77
  this.projectRoot = projectRoot;
76
78
  this.installer = installer;
77
79
 
80
+ // If using src then assume we're linked and find the link root dir
81
+ this.atlaspackLinkRoot =
82
+ process.env.ATLASPACK_REGISTER_USE_SRC === 'true'
83
+ ? path.resolve(__dirname, '../../../..')
84
+ : null;
85
+
78
86
  // @ts-expect-error TS2339
79
87
  this.currentExtensions = Object.keys(Module._extensions).map((e) =>
80
88
  e.substring(1),
@@ -215,32 +223,50 @@ export class NodePackageManager implements PackageManager {
215
223
  return this.fs.statSync(filename);
216
224
  };
217
225
 
218
- if (!filePath.includes(NODE_MODULES)) {
219
- let extname = path.extname(filePath);
220
- if (
221
- (extname === '.ts' ||
222
- extname === '.tsx' ||
223
- extname === '.mts' ||
224
- extname === '.cts') &&
225
- // @ts-expect-error TS2339
226
- !Module._extensions[extname]
227
- ) {
228
- // @ts-expect-error TS2339
229
- let compile = m._compile;
230
- // @ts-expect-error TS2339
231
- m._compile = (code: any, filename: any) => {
232
- let out = transformSync(code, {filename, module: {type: 'commonjs'}});
233
- compile.call(m, out.code, filename);
234
- };
226
+ let extname = path.extname(filePath);
235
227
 
236
- // @ts-expect-error TS2339
237
- Module._extensions[extname] = (m: any, filename: any) => {
238
- // @ts-expect-error TS2339
239
- delete Module._extensions[extname];
240
- // @ts-expect-error TS2339
241
- Module._extensions['.js'](m, filename);
242
- };
228
+ function shouldCompile(atlaspackLinkRoot: string | null): boolean {
229
+ if (filePath.includes(NODE_MODULES)) {
230
+ // Don't compile node_modules
231
+ return false;
232
+ }
233
+
234
+ if (!compileExtensions.has(extname)) {
235
+ // Ignore non-TS files
236
+ return false;
237
+ }
238
+
239
+ if (atlaspackLinkRoot != null) {
240
+ // If we're linked, only compile files outside the linked atlaspack
241
+ // as those are handled by @atlaspack/babel-register
242
+ return !filePath.startsWith(atlaspackLinkRoot);
243
243
  }
244
+
245
+ // @ts-expect-error TS2339
246
+ // Lastly make sure there's no existing loader for this extension
247
+ return !Module._extensions[extname];
248
+ }
249
+
250
+ if (shouldCompile(this.atlaspackLinkRoot)) {
251
+ // @ts-expect-error TS2339
252
+ let compile = m._compile;
253
+ // @ts-expect-error TS2339
254
+ m._compile = (code: any, filename: any) => {
255
+ let out = transformSync(code, {
256
+ filename,
257
+ module: {type: 'commonjs'},
258
+ env: {targets: {node: '18'}},
259
+ });
260
+ compile.call(m, out.code, filename);
261
+ };
262
+
263
+ // @ts-expect-error TS2339
264
+ Module._extensions[extname] = (m: any, filename: any) => {
265
+ // @ts-expect-error TS2339
266
+ delete Module._extensions[extname];
267
+ // @ts-expect-error TS2339
268
+ Module._extensions['.js'](m, filename);
269
+ };
244
270
  }
245
271
 
246
272
  try {