mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
fix(bundle): support importing directories with a package.json from an es module when bundling (#30273)
Some checks are pending
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / test release windows-x86_64 (push) Blocked by required conditions
ci / build libs (push) Blocked by required conditions
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / publish canary (push) Blocked by required conditions
Some checks are pending
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / test release windows-x86_64 (push) Blocked by required conditions
ci / build libs (push) Blocked by required conditions
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / publish canary (push) Blocked by required conditions
This commit is contained in:
parent
6ae4eda86a
commit
efb16e70d3
13 changed files with 66 additions and 25 deletions
|
@ -562,7 +562,9 @@ impl<
|
|||
let maybe_file_type = self.sys.get_file_type(&path);
|
||||
match maybe_file_type {
|
||||
Ok(FileType::Dir) => {
|
||||
if resolution_mode == ResolutionMode::Import {
|
||||
if resolution_mode == ResolutionMode::Import
|
||||
&& !self.resolution_config.bundle_mode
|
||||
{
|
||||
let suggested_file_name = ["index.mjs", "index.js", "index.cjs"]
|
||||
.into_iter()
|
||||
.find(|e| self.sys.is_file(&path.join(e)));
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
{
|
||||
"args": "bundle --quiet main.cjs",
|
||||
"output": "bundle.out"
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __commonJS = (cb, mod) => function __require() {
|
||||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
||||
};
|
||||
|
||||
// node_modules/package/constants/sub.js
|
||||
var require_sub = __commonJS({
|
||||
"node_modules/package/constants/sub.js"(exports, module) {
|
||||
module.exports = 5;
|
||||
}
|
||||
});
|
||||
|
||||
// main.cjs
|
||||
var require_main = __commonJS({
|
||||
"main.cjs"() {
|
||||
var value = require_sub();
|
||||
console.log(value);
|
||||
}
|
||||
});
|
||||
export default require_main();
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"args": "bundle --quiet main.mjs",
|
||||
"output": "bundle.out"
|
||||
}
|
48
tests/specs/bundle/dir_import_package_json/bundle.out
Normal file
48
tests/specs/bundle/dir_import_package_json/bundle.out
Normal file
|
@ -0,0 +1,48 @@
|
|||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __commonJS = (cb, mod) => function __require() {
|
||||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
|
||||
// node_modules/package/constants/sub.js
|
||||
var require_sub = __commonJS({
|
||||
"node_modules/package/constants/sub.js"(exports, module) {
|
||||
module.exports = 5;
|
||||
}
|
||||
});
|
||||
|
||||
// main.cjs
|
||||
var require_main = __commonJS({
|
||||
"main.cjs"() {
|
||||
var value = require_sub();
|
||||
console.log(value);
|
||||
}
|
||||
});
|
||||
|
||||
// node_modules/esm-pkg/index.js
|
||||
var constants = __toESM(require_sub());
|
||||
var esm_pkg_default = constants;
|
||||
|
||||
// main.mjs
|
||||
var import_main = __toESM(require_main(), 1);
|
||||
console.log(esm_pkg_default);
|
3
tests/specs/bundle/dir_import_package_json/main.mjs
Normal file
3
tests/specs/bundle/dir_import_package_json/main.mjs
Normal file
|
@ -0,0 +1,3 @@
|
|||
import constants from "esm-pkg";
|
||||
console.log(constants);
|
||||
import "./main.cjs";
|
5
tests/specs/bundle/dir_import_package_json/node_modules/esm-pkg/index.js
generated
vendored
Normal file
5
tests/specs/bundle/dir_import_package_json/node_modules/esm-pkg/index.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
// this should work when bundling even though it's esm,
|
||||
// but will not work at runtime due to Node's ESM restrictions
|
||||
import * as constants from "package/constants";
|
||||
|
||||
export default constants;
|
3
tests/specs/bundle/dir_import_package_json/node_modules/esm-pkg/package.json
generated
vendored
Normal file
3
tests/specs/bundle/dir_import_package_json/node_modules/esm-pkg/package.json
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"type": "module"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue