@rollup/plugin-node-resolve 15.0.2 → 15.2.0

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/README.md CHANGED
@@ -234,6 +234,25 @@ this.resolve(importee, importer, {
234
234
  });
235
235
  ```
236
236
 
237
+ ## Resolve Options
238
+
239
+ After this plugin resolved an import id to its target file in `node_modules`, it will invoke `this.resolve` again with the resolved id. It will pass the following information in the resolve options:
240
+
241
+ ```js
242
+ this.resolve(resolved.id, importer, {
243
+ custom: {
244
+ 'node-resolve': {
245
+ resolved, // the object with information from node.js resolve
246
+ importee // the original import id
247
+ }
248
+ }
249
+ });
250
+ ```
251
+
252
+ Your plugin can use the `importee` information to map an original import to its resolved file in `node_modules`, in a plugin hook such as `resolveId`.
253
+
254
+ The `resolved` object contains the resolved id, which is passed as the first parameter. It also has a property `moduleSideEffects`, which may contain the value from the npm `package.json` field `sideEffects` or `null`.
255
+
237
256
  ## Meta
238
257
 
239
258
  [CONTRIBUTING](/.github/CONTRIBUTING.md)
package/dist/cjs/index.js CHANGED
@@ -12,7 +12,7 @@ var url = require('url');
12
12
  var resolve = require('resolve');
13
13
  var pluginutils = require('@rollup/pluginutils');
14
14
 
15
- var version = "15.0.2";
15
+ var version = "15.2.0";
16
16
  var peerDependencies = {
17
17
  rollup: "^2.78.0||^3.0.0"
18
18
  };
@@ -1090,11 +1090,18 @@ function nodeResolve(opts = {}) {
1090
1090
  importSpecifierList.push(`./${importee}`);
1091
1091
  }
1092
1092
 
1093
- // TypeScript files may import '.js' to refer to either '.ts' or '.tsx'
1094
- if (importer && importee.endsWith('.js')) {
1095
- for (const ext of ['.ts', '.tsx']) {
1096
- if (importer.endsWith(ext) && extensions.includes(ext)) {
1097
- importSpecifierList.push(importee.replace(/.js$/, ext));
1093
+ // TypeScript files may import '.mjs' or '.cjs' to refer to either '.mts' or '.cts'.
1094
+ // They may also import .js to refer to either .ts or .tsx, and .jsx to refer to .tsx.
1095
+ if (importer && /\.(ts|mts|cts|tsx)$/.test(importer)) {
1096
+ for (const [importeeExt, resolvedExt] of [
1097
+ ['.js', '.ts'],
1098
+ ['.js', '.tsx'],
1099
+ ['.jsx', '.tsx'],
1100
+ ['.mjs', '.mts'],
1101
+ ['.cjs', '.cts']
1102
+ ]) {
1103
+ if (importee.endsWith(importeeExt) && extensions.includes(resolvedExt)) {
1104
+ importSpecifierList.push(importee.slice(0, -importeeExt.length) + resolvedExt);
1098
1105
  }
1099
1106
  }
1100
1107
  }
@@ -1238,7 +1245,7 @@ function nodeResolve(opts = {}) {
1238
1245
  // `moduleSideEffects` information.
1239
1246
  const resolvedResolved = await this.resolve(resolved.id, importer, {
1240
1247
  ...resolveOptions,
1241
- custom: { ...custom, 'node-resolve': { ...custom['node-resolve'], resolved } }
1248
+ custom: { ...custom, 'node-resolve': { ...custom['node-resolve'], resolved, importee } }
1242
1249
  });
1243
1250
  if (resolvedResolved) {
1244
1251
  // Handle plugins that manually make the result external
package/dist/es/index.js CHANGED
@@ -8,7 +8,7 @@ import { pathToFileURL, fileURLToPath } from 'url';
8
8
  import resolve$1 from 'resolve';
9
9
  import { createFilter } from '@rollup/pluginutils';
10
10
 
11
- var version = "15.0.2";
11
+ var version = "15.2.0";
12
12
  var peerDependencies = {
13
13
  rollup: "^2.78.0||^3.0.0"
14
14
  };
@@ -1086,11 +1086,18 @@ function nodeResolve(opts = {}) {
1086
1086
  importSpecifierList.push(`./${importee}`);
1087
1087
  }
1088
1088
 
1089
- // TypeScript files may import '.js' to refer to either '.ts' or '.tsx'
1090
- if (importer && importee.endsWith('.js')) {
1091
- for (const ext of ['.ts', '.tsx']) {
1092
- if (importer.endsWith(ext) && extensions.includes(ext)) {
1093
- importSpecifierList.push(importee.replace(/.js$/, ext));
1089
+ // TypeScript files may import '.mjs' or '.cjs' to refer to either '.mts' or '.cts'.
1090
+ // They may also import .js to refer to either .ts or .tsx, and .jsx to refer to .tsx.
1091
+ if (importer && /\.(ts|mts|cts|tsx)$/.test(importer)) {
1092
+ for (const [importeeExt, resolvedExt] of [
1093
+ ['.js', '.ts'],
1094
+ ['.js', '.tsx'],
1095
+ ['.jsx', '.tsx'],
1096
+ ['.mjs', '.mts'],
1097
+ ['.cjs', '.cts']
1098
+ ]) {
1099
+ if (importee.endsWith(importeeExt) && extensions.includes(resolvedExt)) {
1100
+ importSpecifierList.push(importee.slice(0, -importeeExt.length) + resolvedExt);
1094
1101
  }
1095
1102
  }
1096
1103
  }
@@ -1234,7 +1241,7 @@ function nodeResolve(opts = {}) {
1234
1241
  // `moduleSideEffects` information.
1235
1242
  const resolvedResolved = await this.resolve(resolved.id, importer, {
1236
1243
  ...resolveOptions,
1237
- custom: { ...custom, 'node-resolve': { ...custom['node-resolve'], resolved } }
1244
+ custom: { ...custom, 'node-resolve': { ...custom['node-resolve'], resolved, importee } }
1238
1245
  });
1239
1246
  if (resolvedResolved) {
1240
1247
  // Handle plugins that manually make the result external
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rollup/plugin-node-resolve",
3
- "version": "15.0.2",
3
+ "version": "15.2.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },