Skip to content

Commit 5ebab54

Browse files
Add explicit .ts/.js extension to all imports in src (#15892)
1 parent 8ba5c67 commit 5ebab54

File tree

292 files changed

+1096
-1093
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

292 files changed

+1096
-1093
lines changed

Gulpfile.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ function generateStandalone() {
182182
through.obj(async (file, enc, callback) => {
183183
log("Generating @babel/standalone files");
184184
const pluginConfig = JSON.parse(file.contents);
185-
let imports = `import makeNoopPlugin from "../make-noop-plugin";`;
185+
let imports = `import makeNoopPlugin from "../make-noop-plugin.ts";`;
186186
let exportDecls = "";
187187
let exportsList = "";
188188
let allList = "";

babel.config.js

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ module.exports = function (api) {
7777

7878
let targets = {};
7979
let convertESM = outputType === "script";
80-
/** @type {false | "externals" | "always"} */
81-
let addImportExtension = convertESM ? false : "always";
80+
let replaceTSImportExtension = true;
8281
let ignoreLib = true;
8382
let includeRegeneratorRuntime = false;
8483
let needsPolyfillsForOldNode = false;
@@ -107,7 +106,7 @@ module.exports = function (api) {
107106
case "standalone":
108107
includeRegeneratorRuntime = true;
109108
convertESM = false;
110-
addImportExtension = false;
109+
replaceTSImportExtension = false;
111110
ignoreLib = false;
112111
// rollup-commonjs will converts node_modules to ESM
113112
unambiguousSources.push(
@@ -120,7 +119,7 @@ module.exports = function (api) {
120119
break;
121120
case "rollup":
122121
convertESM = false;
123-
addImportExtension = "externals";
122+
replaceTSImportExtension = false;
124123
ignoreLib = false;
125124
// rollup-commonjs will converts node_modules to ESM
126125
unambiguousSources.push(
@@ -230,9 +229,7 @@ module.exports = function (api) {
230229
assumptions: sourceAssumptions,
231230
plugins: [
232231
transformNamedBabelTypesImportToDestructuring,
233-
addImportExtension
234-
? [pluginAddImportExtension, { when: addImportExtension }]
235-
: null,
232+
replaceTSImportExtension ? pluginReplaceTSImportExtension : null,
236233

237234
[
238235
pluginToggleBooleanFlag,
@@ -787,56 +784,13 @@ function pluginImportMetaUrl({ types: t, template }) {
787784
};
788785
}
789786

790-
function pluginAddImportExtension(api, { when }) {
787+
function pluginReplaceTSImportExtension() {
791788
return {
792789
visitor: {
793790
"ImportDeclaration|ExportDeclaration"({ node }) {
794791
const { source } = node;
795-
if (!source) return;
796-
797-
if (
798-
when === "always" &&
799-
source.value.startsWith(".") &&
800-
!/\.[a-z]+$/.test(source.value)
801-
) {
802-
const dir = pathUtils.dirname(this.filename);
803-
804-
try {
805-
const pkg = JSON.parse(
806-
fs.readFileSync(
807-
pathUtils.join(dir, `${source.value}/package.json`)
808-
),
809-
"utf8"
810-
);
811-
812-
if (pkg.main) source.value = pathUtils.join(source.value, pkg.main);
813-
} catch (_) {}
814-
815-
try {
816-
if (fs.statSync(pathUtils.join(dir, source.value)).isFile()) return;
817-
} catch (_) {}
818-
819-
for (const [src, lib = src] of [["ts", "js"], ["js"], ["cjs"]]) {
820-
try {
821-
fs.statSync(pathUtils.join(dir, `${source.value}.${src}`));
822-
source.value += `.${lib}`;
823-
return;
824-
} catch (_) {}
825-
}
826-
827-
source.value += "/index.js";
828-
}
829-
if (
830-
source.value.startsWith("lodash/") ||
831-
source.value.startsWith("core-js-compat/") ||
832-
source.value === "core-js/stable/index" ||
833-
source.value === "regenerator-runtime/runtime" ||
834-
source.value === "babel-plugin-dynamic-import-node/utils"
835-
) {
836-
source.value += ".js";
837-
}
838-
if (source.value.startsWith("@babel/preset-modules/")) {
839-
source.value += "/index.js";
792+
if (source) {
793+
source.value = source.value.replace(/(\.[mc]?)ts$/, "$1js");
840794
}
841795
},
842796
},

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ module.exports = [
173173
"@babel/development/no-undefined-identifier": "error",
174174
"@babel/development/no-deprecated-clone": "error",
175175
"guard-for-in": "error",
176-
"import/extensions": ["error", { json: "always", cjs: "always" }],
176+
"import/extensions": ["error", "ignorePackages"],
177177
},
178178
},
179179
...compat.extends("plugin:jest/recommended").map(config => {

lib/third-party-libs.d.ts

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,69 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
13
declare module "js-tokens" {
24
// TODO(Babel 8): Remove this
35
export { default } from "js-tokens-BABEL_8_BREAKING-true";
46
export * from "js-tokens-BABEL_8_BREAKING-true";
57
}
68

7-
declare module "@babel/preset-modules/lib/plugins/transform-async-arrows-in-class" {
8-
import { declare } from "@babel/helper-plugin-utils";
9+
declare module "@babel/preset-modules/lib/plugins/transform-async-arrows-in-class/index.js" {
10+
import type { declare } from "@babel/helper-plugin-utils";
911
let plugin: ReturnType<typeof declare>;
10-
let exports: {default: typeof plugin};
12+
let exports: { default: typeof plugin };
1113
export = exports;
1214
}
13-
declare module "@babel/preset-modules/lib/plugins/transform-edge-default-parameters" {
14-
import { declare } from "@babel/helper-plugin-utils";
15+
declare module "@babel/preset-modules/lib/plugins/transform-edge-default-parameters/index.js" {
16+
import type { declare } from "@babel/helper-plugin-utils";
1517
let plugin: ReturnType<typeof declare>;
16-
let exports: {default: typeof plugin};
18+
let exports: { default: typeof plugin };
1719
export = exports;
1820
}
19-
declare module "@babel/preset-modules/lib/plugins/transform-edge-function-name" {
20-
import { declare } from "@babel/helper-plugin-utils";
21+
declare module "@babel/preset-modules/lib/plugins/transform-edge-function-name/index.js" {
22+
import type { declare } from "@babel/helper-plugin-utils";
2123
let plugin: ReturnType<typeof declare>;
22-
let exports: {default: typeof plugin};
24+
let exports: { default: typeof plugin };
2325
export = exports;
2426
}
25-
declare module "@babel/preset-modules/lib/plugins/transform-tagged-template-caching" {
26-
import { declare } from "@babel/helper-plugin-utils";
27+
declare module "@babel/preset-modules/lib/plugins/transform-tagged-template-caching/index.js" {
28+
import type { declare } from "@babel/helper-plugin-utils";
2729
let plugin: ReturnType<typeof declare>;
28-
let exports: {default: typeof plugin};
30+
let exports: { default: typeof plugin };
2931
export = exports;
3032
}
31-
declare module "@babel/preset-modules/lib/plugins/transform-safari-block-shadowing" {
32-
import { declare } from "@babel/helper-plugin-utils";
33+
declare module "@babel/preset-modules/lib/plugins/transform-safari-block-shadowing/index.js" {
34+
import type { declare } from "@babel/helper-plugin-utils";
3335
let plugin: ReturnType<typeof declare>;
34-
let exports: {default: typeof plugin};
36+
let exports: { default: typeof plugin };
3537
export = exports;
3638
}
37-
declare module "@babel/preset-modules/lib/plugins/transform-safari-for-shadowing" {
38-
import { declare } from "@babel/helper-plugin-utils";
39+
declare module "@babel/preset-modules/lib/plugins/transform-safari-for-shadowing/index.js" {
40+
import type { declare } from "@babel/helper-plugin-utils";
3941
let plugin: ReturnType<typeof declare>;
40-
let exports: {default: typeof plugin};
42+
let exports: { default: typeof plugin };
4143
export = exports;
4244
}
4345
declare module "babel-plugin-polyfill-corejs2" {
44-
import { declare } from "@babel/helper-plugin-utils";
46+
import type { declare } from "@babel/helper-plugin-utils";
4547
let plugin: ReturnType<typeof declare>;
46-
let exports: {default: typeof plugin};
48+
let exports: { default: typeof plugin };
4749
export = exports;
4850
}
4951
declare module "babel-plugin-polyfill-corejs3" {
50-
import { declare } from "@babel/helper-plugin-utils";
52+
import type { declare } from "@babel/helper-plugin-utils";
5153
let plugin: ReturnType<typeof declare>;
52-
let exports: {default: typeof plugin};
54+
let exports: { default: typeof plugin };
5355
export = exports;
5456
}
5557
declare module "babel-plugin-polyfill-regenerator" {
56-
import { declare } from "@babel/helper-plugin-utils";
58+
import type { declare } from "@babel/helper-plugin-utils";
5759
let plugin: ReturnType<typeof declare>;
58-
let exports: {default: typeof plugin};
60+
let exports: { default: typeof plugin };
5961
export = exports;
6062
}
6163

6264
declare module "regenerator-transform" {
63-
import { declare } from "@babel/helper-plugin-utils";
65+
import type { declare } from "@babel/helper-plugin-utils";
6466
let plugin: ReturnType<typeof declare>;
65-
let exports: {default: typeof plugin};
67+
let exports: { default: typeof plugin };
6668
export = exports;
6769
}

packages/babel-cli/src/babel/dir.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import slash from "slash";
22
import path from "path";
33
import fs from "fs";
44

5-
import * as util from "./util";
6-
import * as watcher from "./watcher";
7-
import type { CmdOptions } from "./options";
5+
import * as util from "./util.ts";
6+
import * as watcher from "./watcher.ts";
7+
import type { CmdOptions } from "./options.ts";
88

99
const FILE_TYPE = Object.freeze({
1010
NON_COMPILABLE: "NON_COMPILABLE",

packages/babel-cli/src/babel/file.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import slash from "slash";
44
import path from "path";
55
import fs from "fs";
66

7-
import * as util from "./util";
8-
import type { CmdOptions } from "./options";
9-
import * as watcher from "./watcher";
7+
import * as util from "./util.ts";
8+
import type { CmdOptions } from "./options.ts";
9+
import * as watcher from "./watcher.ts";
1010

1111
import type {
1212
EncodedSourceMap,

packages/babel-cli/src/babel/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env node
22

3-
import parseArgv from "./options";
4-
import dirCommand from "./dir";
5-
import fileCommand from "./file";
3+
import parseArgv from "./options.ts";
4+
import dirCommand from "./dir.ts";
5+
import fileCommand from "./file.ts";
66

77
const opts = parseArgv(process.argv);
88

packages/babel-cli/src/babel/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as babel from "@babel/core";
33
import path from "path";
44
import fs from "fs";
55

6-
import * as watcher from "./watcher";
6+
import * as watcher from "./watcher.ts";
77

88
import type { FileResult, InputOptions } from "@babel/core";
99

packages/babel-core/src/config/cache-contexts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Targets } from "@babel/helper-compilation-targets";
22

3-
import type { ConfigContext } from "./config-chain";
4-
import type { CallerMetadata } from "./validation/options";
3+
import type { ConfigContext } from "./config-chain.ts";
4+
import type { CallerMetadata } from "./validation/options.ts";
55

66
export type { ConfigContext as FullConfig };
77

packages/babel-core/src/config/caching.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
onFirstPause,
77
waitFor,
88
isThenable,
9-
} from "../gensync-utils/async";
10-
import { isIterableIterator } from "./util";
9+
} from "../gensync-utils/async.ts";
10+
import { isIterableIterator } from "./util.ts";
1111

1212
export type { CacheConfigurator };
1313

packages/babel-core/src/config/config-chain.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
import path from "path";
44
import buildDebug from "debug";
55
import type { Handler } from "gensync";
6-
import { validate } from "./validation/options";
6+
import { validate } from "./validation/options.ts";
77
import type {
88
ValidatedOptions,
99
IgnoreList,
1010
ConfigApplicableTest,
1111
BabelrcSearch,
1212
CallerMetadata,
1313
IgnoreItem,
14-
} from "./validation/options";
15-
import pathPatternToRegex from "./pattern-to-regex";
16-
import { ConfigPrinter, ChainFormatter } from "./printer";
17-
import type { ReadonlyDeepArray } from "./helpers/deep-array";
14+
} from "./validation/options.ts";
15+
import pathPatternToRegex from "./pattern-to-regex.ts";
16+
import { ConfigPrinter, ChainFormatter } from "./printer.ts";
17+
import type { ReadonlyDeepArray } from "./helpers/deep-array.ts";
1818

19-
import { endHiddenCallStack } from "../errors/rewrite-stack-trace";
20-
import ConfigError from "../errors/config-error";
21-
import type { PluginAPI, PresetAPI } from "./helpers/config-api";
19+
import { endHiddenCallStack } from "../errors/rewrite-stack-trace.ts";
20+
import ConfigError from "../errors/config-error.ts";
21+
import type { PluginAPI, PresetAPI } from "./helpers/config-api.ts";
2222

2323
const debug = buildDebug("babel:config:config-chain");
2424

@@ -27,20 +27,20 @@ import {
2727
findRelativeConfig,
2828
findRootConfig,
2929
loadConfig,
30-
} from "./files";
31-
import type { ConfigFile, IgnoreFile, FilePackageData } from "./files";
30+
} from "./files/index.ts";
31+
import type { ConfigFile, IgnoreFile, FilePackageData } from "./files/index.ts";
3232

33-
import { makeWeakCacheSync, makeStrongCacheSync } from "./caching";
33+
import { makeWeakCacheSync, makeStrongCacheSync } from "./caching.ts";
3434

3535
import {
3636
createCachedDescriptors,
3737
createUncachedDescriptors,
38-
} from "./config-descriptors";
38+
} from "./config-descriptors.ts";
3939
import type {
4040
UnloadedDescriptor,
4141
OptionsAndDescriptors,
4242
ValidatedFile,
43-
} from "./config-descriptors";
43+
} from "./config-descriptors.ts";
4444

4545
export type ConfigChain = {
4646
plugins: Array<UnloadedDescriptor<PluginAPI>>;

packages/babel-core/src/config/config-descriptors.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import gensync, { type Handler } from "gensync";
2-
import { once } from "../gensync-utils/functional";
2+
import { once } from "../gensync-utils/functional.ts";
33

4-
import { loadPlugin, loadPreset } from "./files";
4+
import { loadPlugin, loadPreset } from "./files/index.ts";
55

6-
import { getItemDescriptor } from "./item";
6+
import { getItemDescriptor } from "./item.ts";
77

88
import {
99
makeWeakCacheSync,
1010
makeStrongCacheSync,
1111
makeStrongCache,
12-
} from "./caching";
13-
import type { CacheConfigurator } from "./caching";
12+
} from "./caching.ts";
13+
import type { CacheConfigurator } from "./caching.ts";
1414

1515
import type {
1616
ValidatedOptions,
1717
PluginList,
1818
PluginItem,
19-
} from "./validation/options";
19+
} from "./validation/options.ts";
2020

21-
import { resolveBrowserslistConfigFile } from "./resolve-targets";
22-
import type { PluginAPI, PresetAPI } from "./helpers/config-api";
21+
import { resolveBrowserslistConfigFile } from "./resolve-targets.ts";
22+
import type { PluginAPI, PresetAPI } from "./helpers/config-api.ts";
2323

2424
// Represents a config object and functions to lazily load the descriptors
2525
// for the plugins and presets so we don't load the plugins/presets unless

0 commit comments

Comments
 (0)