-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not handle path that can’t be resolved (#612)
- Loading branch information
Showing
8 changed files
with
200 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "redirect-js-no-resolve-test", | ||
"version": "1.0.0", | ||
"private": true, | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { defineConfig } from '@rslib/core'; | ||
import { generateBundleEsmConfig } from 'test-helper'; | ||
|
||
export default defineConfig({ | ||
lib: [ | ||
// 0 default | ||
generateBundleEsmConfig({ | ||
bundle: false, | ||
output: { | ||
distPath: { | ||
root: 'dist/default/esm', | ||
}, | ||
}, | ||
}), | ||
// 1 js.path: false | ||
generateBundleEsmConfig({ | ||
bundle: false, | ||
output: { | ||
distPath: { | ||
root: 'dist/js-path-false/esm', | ||
}, | ||
}, | ||
redirect: { | ||
js: { | ||
path: false, | ||
}, | ||
}, | ||
}), | ||
// 2 js.extension: false | ||
generateBundleEsmConfig({ | ||
bundle: false, | ||
output: { | ||
distPath: { | ||
root: 'dist/js-extension-false/esm', | ||
}, | ||
}, | ||
redirect: { | ||
js: { | ||
extension: false, | ||
}, | ||
}, | ||
}), | ||
], | ||
resolve: { | ||
alias: { | ||
'~': './src', | ||
}, | ||
}, | ||
source: { | ||
entry: { | ||
index: './src/**', | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import lodash from 'lodash'; | ||
import bar from './bar.js'; | ||
import foo from './foo'; | ||
|
||
export default lodash.toUpper(foo + bar); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import path from 'node:path'; | ||
import stripAnsi from 'strip-ansi'; | ||
import { buildAndGetResults, proxyConsole, queryContent } from 'test-helper'; | ||
import { expect, test } from 'vitest'; | ||
|
||
test('redirect.js default', async () => { | ||
const fixturePath = path.resolve(__dirname, './js-not-resolve'); | ||
const { logs } = proxyConsole(); | ||
const contents = (await buildAndGetResults({ fixturePath, lib: ['esm0'] })) | ||
.contents; | ||
|
||
const logStrings = logs | ||
.map((log) => stripAnsi(log)) | ||
.filter((log) => log.startsWith('warn')) | ||
.sort(); | ||
|
||
expect(logStrings).toMatchInlineSnapshot( | ||
` | ||
[ | ||
"warn Failed to resolve module "./bar.js" from <ROOT>/tests/integration/redirect/js-not-resolve/src/index.js. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.", | ||
"warn Failed to resolve module "./foo" from <ROOT>/tests/integration/redirect/js-not-resolve/src/index.js. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.", | ||
"warn Failed to resolve module "lodash" from <ROOT>/tests/integration/redirect/js-not-resolve/src/index.js. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.", | ||
] | ||
`, | ||
); | ||
|
||
const { content: indexContent } = queryContent( | ||
contents.esm0!, | ||
/esm\/index\.js/, | ||
); | ||
|
||
expect(indexContent).toMatchInlineSnapshot(` | ||
"import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; | ||
import * as __WEBPACK_EXTERNAL_MODULE__bar_js_69b41beb__ from "./bar.js"; | ||
import * as __WEBPACK_EXTERNAL_MODULE__foo_js_fdf5aa2d__ from "./foo.js"; | ||
const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_js_fdf5aa2d__["default"] + __WEBPACK_EXTERNAL_MODULE__bar_js_69b41beb__["default"]); | ||
export { src_rslib_entry_ as default }; | ||
" | ||
`); | ||
}); | ||
|
||
test('redirect.js.path false', async () => { | ||
const fixturePath = path.resolve(__dirname, './js-not-resolve'); | ||
const { logs } = proxyConsole(); | ||
const contents = (await buildAndGetResults({ fixturePath, lib: ['esm1'] })) | ||
.contents; | ||
|
||
const logStrings = logs | ||
.map((log) => stripAnsi(log)) | ||
.filter((log) => log.startsWith('warn')); | ||
|
||
expect(logStrings.length).toBe(0); | ||
|
||
const { content: indexContent } = queryContent( | ||
contents.esm1!, | ||
/esm\/index\.js/, | ||
); | ||
|
||
expect(indexContent).toMatchInlineSnapshot(` | ||
"import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; | ||
import * as __WEBPACK_EXTERNAL_MODULE__bar_js_69b41beb__ from "./bar.js"; | ||
import * as __WEBPACK_EXTERNAL_MODULE__foo_js_fdf5aa2d__ from "./foo.js"; | ||
const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_js_fdf5aa2d__["default"] + __WEBPACK_EXTERNAL_MODULE__bar_js_69b41beb__["default"]); | ||
export { src_rslib_entry_ as default }; | ||
" | ||
`); | ||
}); | ||
|
||
test('redirect.js.extension: false', async () => { | ||
const fixturePath = path.resolve(__dirname, './js-not-resolve'); | ||
const { logs } = proxyConsole(); | ||
const contents = (await buildAndGetResults({ fixturePath, lib: ['esm2'] })) | ||
.contents; | ||
|
||
const logStrings = logs | ||
.map((log) => stripAnsi(log)) | ||
.filter((log) => log.startsWith('warn')) | ||
.sort(); | ||
|
||
expect(logStrings).toMatchInlineSnapshot( | ||
` | ||
[ | ||
"warn Failed to resolve module "./bar.js" from <ROOT>/tests/integration/redirect/js-not-resolve/src/index.js. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.", | ||
"warn Failed to resolve module "./foo" from <ROOT>/tests/integration/redirect/js-not-resolve/src/index.js. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.", | ||
"warn Failed to resolve module "lodash" from <ROOT>/tests/integration/redirect/js-not-resolve/src/index.js. If it's an npm package, consider adding it to dependencies or peerDependencies in package.json to make it externalized.", | ||
] | ||
`, | ||
); | ||
|
||
const { content: indexContent } = queryContent( | ||
contents.esm2!, | ||
/esm\/index\.js/, | ||
); | ||
|
||
expect(indexContent).toMatchInlineSnapshot(` | ||
"import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; | ||
import * as __WEBPACK_EXTERNAL_MODULE__bar_js_69b41beb__ from "./bar.js"; | ||
import * as __WEBPACK_EXTERNAL_MODULE__foo_23da6eef__ from "./foo"; | ||
const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_23da6eef__["default"] + __WEBPACK_EXTERNAL_MODULE__bar_js_69b41beb__["default"]); | ||
export { src_rslib_entry_ as default }; | ||
" | ||
`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters