Skip to content

Commit

Permalink
refactor: explicit extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Jul 31, 2023
1 parent 990f542 commit ef5c221
Show file tree
Hide file tree
Showing 26 changed files with 56 additions and 57 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ Native Node.js import mapping supports conditional imports (eg. resolving differ
// ...

"imports": {
// Mapping '~utils' to './src/utils'
"~utils": "./src/utils",
// Mapping '~utils' to './src/utils.js'
"~utils": "./src/utils.js",

// Native Node.js import mapping (can't reference ./src)
"#internal-package": "./vendors/package/index.js",
Expand Down
16 changes: 8 additions & 8 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import fs from 'fs';
import { cli } from 'cleye';
import { rollup, watch } from 'rollup';
import { version } from '../package.json';
import { readPackageJson } from './utils/read-package-json';
import { getExportEntries } from './utils/parse-package-json/get-export-entries';
import { getAliases } from './utils/parse-package-json/get-aliases';
import { normalizePath } from './utils/normalize-path';
import { getSourcePath } from './utils/get-source-path';
import { getRollupConfigs } from './utils/get-rollup-configs';
import { tsconfig } from './utils/tsconfig';
import { log } from './utils/log';
import { readPackageJson } from './utils/read-package-json.js';
import { getExportEntries } from './utils/parse-package-json/get-export-entries.js';
import { getAliases } from './utils/parse-package-json/get-aliases.js';
import { normalizePath } from './utils/normalize-path.js';
import { getSourcePath } from './utils/get-source-path.js';
import { getRollupConfigs } from './utils/get-rollup-configs.js';
import { tsconfig } from './utils/tsconfig.js';
import { log } from './utils/log.js';

const { stringify } = JSON;

Expand Down
1 change: 0 additions & 1 deletion src/local-typescript-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ function getLocalTypescriptPath() {
}
}

// eslint-disable-next-line node/global-require
export default require(getLocalTypescriptPath());

Check failure on line 12 in src/local-typescript-loader.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Unexpected require()
14 changes: 7 additions & 7 deletions src/utils/get-rollup-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import json from '@rollup/plugin-json';
import alias from '@rollup/plugin-alias';
import replace from '@rollup/plugin-replace';
import type { PackageJson } from 'type-fest';
import type { ExportEntry, AliasMap } from '../types';
import { isFormatEsm, createRequire } from './rollup-plugins/create-require';
import { esbuildTransform, esbuildMinify } from './rollup-plugins/esbuild';
import { externalizeNodeBuiltins } from './rollup-plugins/externalize-node-builtins';
import { patchBinary } from './rollup-plugins/patch-binary';
import { resolveTypescriptMjsCts } from './rollup-plugins/resolve-typescript-mjs-cjs';
import { getExternalDependencies } from './parse-package-json/get-external-dependencies';
import type { ExportEntry, AliasMap } from '../types.js';
import { isFormatEsm, createRequire } from './rollup-plugins/create-require.js';
import { esbuildTransform, esbuildMinify } from './rollup-plugins/esbuild.js';
import { externalizeNodeBuiltins } from './rollup-plugins/externalize-node-builtins.js';
import { patchBinary } from './rollup-plugins/patch-binary.js';
import { resolveTypescriptMjsCts } from './rollup-plugins/resolve-typescript-mjs-cjs.js';
import { getExternalDependencies } from './parse-package-json/get-external-dependencies.js';

type Options = {
minify: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/get-source-path.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ExportEntry } from '../types';
import { fsExists } from './fs-exists';
import type { ExportEntry } from '../types.js';
import { fsExists } from './fs-exists.js';

const { stringify } = JSON;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/parse-package-json/get-aliases.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import type { PackageJson } from 'type-fest';
import type { AliasMap } from '../../types';
import type { AliasMap } from '../../types.js';

export const getAliases = (
{ imports }: PackageJson,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/parse-package-json/get-export-entries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PackageJson } from 'type-fest';
import type { PackageType, ExportEntry } from '../../types';
import { normalizePath } from '../normalize-path';
import type { PackageType, ExportEntry } from '../../types.js';
import { normalizePath } from '../normalize-path.js';

const getFileType = (filePath: string): PackageType | undefined => {
if (filePath.endsWith('.mjs')) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/read-package-json.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import path from 'path';
import type { PackageJson } from 'type-fest';
import { fsExists } from './fs-exists';
import { fsExists } from './fs-exists.js';

export const readPackageJson = async (directoryPath: string): Promise<PackageJson> => {
const packageJsonPath = path.join(directoryPath, 'package.json');
Expand Down
2 changes: 1 addition & 1 deletion src/utils/rollup-plugins/esbuild.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Plugin, InternalModuleFormat } from 'rollup';
import { createFilter } from '@rollup/pluginutils';
import { transform, type TransformOptions, type Format } from 'esbuild';
import { tsconfig } from '../tsconfig';
import { tsconfig } from '../tsconfig.js';

export function esbuildTransform(
options?: TransformOptions,
Expand Down
2 changes: 1 addition & 1 deletion tests/fixture-package/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import value from './value.js';
import { Component } from './component.tsx';
import { sayHello } from './utils';
import { sayHello } from './utils.js';
import { sayHello as sayHelloMjs } from './mjs.mjs';
import { sayHello as sayHelloMts } from './mts.mts';
import { sayHello as sayHelloCjs } from './cjs.cjs';
Expand Down
4 changes: 2 additions & 2 deletions tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const nodeVersions = [
for (const nodeVersion of nodeVersions) {
const node = await getNode(nodeVersion);
await describe(`Node ${node.version}`, ({ runTestSuite }) => {
runTestSuite(import('./specs/error-cases'), node.path);
runTestSuite(import('./specs/builds'), node.path);
runTestSuite(import('./specs/error-cases.js'), node.path);
runTestSuite(import('./specs/builds/index.js'), node.path);
});
}
})();
2 changes: 1 addition & 1 deletion tests/specs/builds/bin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs/promises';
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
import { pkgroll } from '../../utils';
import { pkgroll } from '../../utils.js';

export default testSuite(({ describe }, nodePath: string) => {
describe('bin', ({ test }) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/builds/dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
import { pkgroll, installTypeScript } from '../../utils';
import { pkgroll, installTypeScript } from '../../utils.js';

export default testSuite(({ describe }, nodePath: string) => {
describe('dependencies', ({ test }) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/builds/env.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
import { pkgroll } from '../../utils';
import { pkgroll } from '../../utils.js';

export default testSuite(({ describe }, nodePath: string) => {
describe('env', ({ test }) => {
Expand Down
26 changes: 13 additions & 13 deletions tests/specs/builds/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import { testSuite } from 'manten';

export default testSuite(({ describe }, nodePath: string) => {
describe('builds', async ({ runTestSuite }) => {
runTestSuite(import('./output-commonjs'), nodePath);
runTestSuite(import('./output-module'), nodePath);
runTestSuite(import('./output-types'), nodePath);
runTestSuite(import('./env'), nodePath);
runTestSuite(import('./target'), nodePath);
runTestSuite(import('./minification'), nodePath);
runTestSuite(import('./package-exports'), nodePath);
runTestSuite(import('./package-imports'), nodePath);
runTestSuite(import('./bin'), nodePath);
runTestSuite(import('./dependencies'), nodePath);
runTestSuite(import('./src-dist'), nodePath);
runTestSuite(import('./sourcemap'), nodePath);
runTestSuite(import('./typescript'), nodePath);
runTestSuite(import('./output-commonjs.js'), nodePath);
runTestSuite(import('./output-module.js'), nodePath);
runTestSuite(import('./output-types.js'), nodePath);
runTestSuite(import('./env.js'), nodePath);
runTestSuite(import('./target.js'), nodePath);
runTestSuite(import('./minification.js'), nodePath);
runTestSuite(import('./package-exports.js'), nodePath);
runTestSuite(import('./package-imports.js'), nodePath);
runTestSuite(import('./bin.js'), nodePath);
runTestSuite(import('./dependencies.js'), nodePath);
runTestSuite(import('./src-dist.js'), nodePath);
runTestSuite(import('./sourcemap.js'), nodePath);
runTestSuite(import('./typescript.js'), nodePath);
});
});
2 changes: 1 addition & 1 deletion tests/specs/builds/minification.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
import { pkgroll } from '../../utils';
import { pkgroll } from '../../utils.js';

export default testSuite(({ describe }, nodePath: string) => {
describe('minification', ({ test }) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/builds/output-commonjs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
import { pkgroll } from '../../utils';
import { pkgroll } from '../../utils.js';

export default testSuite(({ describe }, nodePath: string) => {
describe('output: commonjs', ({ test }) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/builds/output-module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
import { pkgroll } from '../../utils';
import { pkgroll } from '../../utils.js';

export default testSuite(({ describe }, nodePath: string) => {
describe('output: module', ({ test }) => {
Expand Down
4 changes: 2 additions & 2 deletions tests/specs/builds/output-types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
import { pkgroll, installTypeScript } from '../../utils';
import { pkgroll, installTypeScript } from '../../utils.js';

export default testSuite(({ describe }, nodePath: string) => {
describe('types', ({ test }) => {
Expand Down Expand Up @@ -99,7 +99,7 @@ export default testSuite(({ describe }, nodePath: string) => {

await fixture.writeJson('package.json', {
exports: {
'./utils': {
'./utils.js': {
types: './dist/utils.d.ts',
},
'./nested': {
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/builds/package-exports.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
import { pkgroll } from '../../utils';
import { pkgroll } from '../../utils.js';

export default testSuite(({ describe }, nodePath: string) => {
describe('package exports', ({ test }) => {
Expand Down
4 changes: 2 additions & 2 deletions tests/specs/builds/package-imports.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
import { pkgroll } from '../../utils';
import { pkgroll } from '../../utils.js';

export default testSuite(({ describe }, nodePath: string) => {
describe('package imports', ({ test }) => {
Expand All @@ -14,7 +14,7 @@ export default testSuite(({ describe }, nodePath: string) => {
},
});
await fixture.writeFile('src/entry.ts', `
import { sayGoodbye } from '~/utils';
import { sayGoodbye } from '~/utils.js';
console.log(sayGoodbye);
`);

Expand Down
2 changes: 1 addition & 1 deletion tests/specs/builds/sourcemap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
import { pkgroll } from '../../utils';
import { pkgroll } from '../../utils.js';

export default testSuite(({ describe }, nodePath: string) => {
describe('generate sourcemap', ({ test }) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/builds/src-dist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path';
import fs from 'fs/promises';
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
import { pkgroll, installTypeScript } from '../../utils';
import { pkgroll, installTypeScript } from '../../utils.js';

export default testSuite(({ describe }, nodePath: string) => {
describe('change src', ({ test }) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/builds/target.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
import { pkgroll, installTypeScript } from '../../utils';
import { pkgroll, installTypeScript } from '../../utils.js';

export default testSuite(({ describe }, nodePath: string) => {
describe('target', ({ describe, test }) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/builds/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
import { pkgroll } from '../../utils';
import { pkgroll } from '../../utils.js';

export default testSuite(({ describe }, nodePath: string) => {
describe('TypeScript', ({ test }) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/error-cases.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
import { pkgroll } from '../utils';
import { pkgroll } from '../utils.js';

export default testSuite(({ describe }, nodePath: string) => {
describe('Error handling', ({ test }) => {
Expand Down

0 comments on commit ef5c221

Please sign in to comment.