From 85d6e9be07af7bb788594b21a986636657d86f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 1 Sep 2023 14:24:50 +0900 Subject: [PATCH] fix(es/module): Revert #7901 (#7906) **Description:** I'm reverting #7901 because it caused a regression in next.js CI. https://github.com/vercel/next.js/pull/54653 **Related issue:** - Reverts #7901. --- .../tests/fixture/deno/paths/issue-2126/output/src/index.ts | 2 +- .../tests/fixture/deno/paths/issue-2724/output/src/index.ts | 2 +- .../fixture/deno/paths/issue-2753/1/output/src/index.ts | 2 +- .../tests/fixture/deno/paths/issue-2844/output/src/index.ts | 4 ++-- .../tests/fixture/issues-6xxx/6782/1/output/src/index.ts | 2 +- .../tests/fixture/issues-7xxx/7417/output/src/lib/foo.ts | 2 +- crates/swc/tests/fixture/issues-7xxx/7829/1/output/1.js | 2 +- crates/swc_ecma_transforms_module/src/path.rs | 6 +++++- .../tests/fixture-manual/issue-4730/output/index.js | 4 ++-- .../tests/paths/issue-7417/output/index.ts | 2 +- node-swc/__tests__/transform/issue_4730_test.mjs | 4 ++-- 11 files changed, 18 insertions(+), 14 deletions(-) diff --git a/crates/swc/tests/fixture/deno/paths/issue-2126/output/src/index.ts b/crates/swc/tests/fixture/deno/paths/issue-2126/output/src/index.ts index c423c538ce18..da767706d2a2 100644 --- a/crates/swc/tests/fixture/deno/paths/issue-2126/output/src/index.ts +++ b/crates/swc/tests/fixture/deno/paths/issue-2126/output/src/index.ts @@ -2,5 +2,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); -const _a = require("../packages/a/src/index.js"); +const _a = require("../packages/a/src"); console.log(`${(0, _a.displayA)()}`); diff --git a/crates/swc/tests/fixture/deno/paths/issue-2724/output/src/index.ts b/crates/swc/tests/fixture/deno/paths/issue-2724/output/src/index.ts index de3d66a11aa8..e44f75ab8257 100644 --- a/crates/swc/tests/fixture/deno/paths/issue-2724/output/src/index.ts +++ b/crates/swc/tests/fixture/deno/paths/issue-2724/output/src/index.ts @@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", { }); const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard"); (async function() { - const { displayA } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard._(require("../packages/a/src/index.js"))); + const { displayA } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard._(require("../packages/a/src"))); console.log(displayA()); })(); diff --git a/crates/swc/tests/fixture/deno/paths/issue-2753/1/output/src/index.ts b/crates/swc/tests/fixture/deno/paths/issue-2753/1/output/src/index.ts index eadc714af569..70dcd7f1632c 100644 --- a/crates/swc/tests/fixture/deno/paths/issue-2753/1/output/src/index.ts +++ b/crates/swc/tests/fixture/deno/paths/issue-2753/1/output/src/index.ts @@ -1,2 +1,2 @@ -import test from "./utils/index.js"; +import test from "./utils"; test(); diff --git a/crates/swc/tests/fixture/deno/paths/issue-2844/output/src/index.ts b/crates/swc/tests/fixture/deno/paths/issue-2844/output/src/index.ts index 3e9d645d4730..347a167bd2a8 100644 --- a/crates/swc/tests/fixture/deno/paths/issue-2844/output/src/index.ts +++ b/crates/swc/tests/fixture/deno/paths/issue-2844/output/src/index.ts @@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); require("./core/module/moduleFile"); -require("./core/utils/index.js"); +require("./core/utils"); require("./core/utilFile"); -require("./utils/index.js"); +require("./utils"); console.log("SUCCESS"); diff --git a/crates/swc/tests/fixture/issues-6xxx/6782/1/output/src/index.ts b/crates/swc/tests/fixture/issues-6xxx/6782/1/output/src/index.ts index 365cee776af6..a164355829e3 100644 --- a/crates/swc/tests/fixture/issues-6xxx/6782/1/output/src/index.ts +++ b/crates/swc/tests/fixture/issues-6xxx/6782/1/output/src/index.ts @@ -1 +1 @@ -import{config}from"../config/index.js";const main=()=>config();main(); +import{config}from"../config";const main=()=>config();main(); diff --git a/crates/swc/tests/fixture/issues-7xxx/7417/output/src/lib/foo.ts b/crates/swc/tests/fixture/issues-7xxx/7417/output/src/lib/foo.ts index a1ef27ff7f79..2ec72f7e4bf0 100644 --- a/crates/swc/tests/fixture/issues-7xxx/7417/output/src/lib/foo.ts +++ b/crates/swc/tests/fixture/issues-7xxx/7417/output/src/lib/foo.ts @@ -9,7 +9,7 @@ Object.defineProperty(exports, "default", { } }); const _interop_require_default = require("@swc/helpers/_/_interop_require_default"); -const _ = /*#__PURE__*/ _interop_require_default._(require("./index.js")); +const _ = /*#__PURE__*/ _interop_require_default._(require(".")); function bar() { console.log(_.default); } diff --git a/crates/swc/tests/fixture/issues-7xxx/7829/1/output/1.js b/crates/swc/tests/fixture/issues-7xxx/7829/1/output/1.js index f8527ad825f5..90ba05422402 100644 --- a/crates/swc/tests/fixture/issues-7xxx/7829/1/output/1.js +++ b/crates/swc/tests/fixture/issues-7xxx/7829/1/output/1.js @@ -1,2 +1,2 @@ -import { fn } from "./libs/pkg/src/index.js"; +import { fn } from "./libs/pkg/src"; console.log(fn); diff --git a/crates/swc_ecma_transforms_module/src/path.rs b/crates/swc_ecma_transforms_module/src/path.rs index f1f555988436..57507cee7840 100644 --- a/crates/swc_ecma_transforms_module/src/path.rs +++ b/crates/swc_ecma_transforms_module/src/path.rs @@ -306,7 +306,11 @@ fn to_specifier(mut target_path: PathBuf, orig_filename: Option<&str>) -> JsWord target_path.set_extension("js"); } } else if is_resolved_as_ts && is_resolved_as_index { - target_path.set_extension("js"); + if orig_filename == "index" { + target_path.set_extension(""); + } else { + target_path.pop(); + } } } else { target_path.set_extension(""); diff --git a/crates/swc_ecma_transforms_module/tests/fixture-manual/issue-4730/output/index.js b/crates/swc_ecma_transforms_module/tests/fixture-manual/issue-4730/output/index.js index 0ae50685d6dd..adeea09e9a98 100644 --- a/crates/swc_ecma_transforms_module/tests/fixture-manual/issue-4730/output/index.js +++ b/crates/swc_ecma_transforms_module/tests/fixture-manual/issue-4730/output/index.js @@ -1,6 +1,6 @@ -import { displayB } from "../packages/b/src/index.js"; +import { displayB } from "../packages/b/src"; async function display() { - const displayA = await import("../packages/a/src/index.js").then((c)=>c.displayA); + const displayA = await import("../packages/a/src").then((c)=>c.displayA); console.log(displayA()); console.log(displayB()); } diff --git a/crates/swc_ecma_transforms_module/tests/paths/issue-7417/output/index.ts b/crates/swc_ecma_transforms_module/tests/paths/issue-7417/output/index.ts index bd56226a5a2e..d2b5aa4bb414 100644 --- a/crates/swc_ecma_transforms_module/tests/paths/issue-7417/output/index.ts +++ b/crates/swc_ecma_transforms_module/tests/paths/issue-7417/output/index.ts @@ -1,4 +1,4 @@ -import o from "./index.js"; +import o from "."; export default function bar() { console.log(o); } diff --git a/node-swc/__tests__/transform/issue_4730_test.mjs b/node-swc/__tests__/transform/issue_4730_test.mjs index 51dc1adcb382..8f00a8f092e2 100644 --- a/node-swc/__tests__/transform/issue_4730_test.mjs +++ b/node-swc/__tests__/transform/issue_4730_test.mjs @@ -38,9 +38,9 @@ it("should work", async () => { value: true }); const _interop_require_wildcard = require(\\"@swc/helpers/_/_interop_require_wildcard\\"); - const _b = require(\\"../packages/b/src/index.js\\"); + const _b = require(\\"../packages/b/src\\"); async function display() { - const displayA = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard._(require(\\"../packages/a/src/index.js\\"))).then((c)=>c.displayA); + const displayA = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard._(require(\\"../packages/a/src\\"))).then((c)=>c.displayA); console.log(displayA()); console.log((0, _b.displayB)()); }