-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable autoExtension by default (#70)
- Loading branch information
1 parent
5b4384e
commit b9ae23e
Showing
6 changed files
with
74 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,41 @@ | ||
import { extname, join } from 'node:path'; | ||
import { buildAndGetResults } from '@e2e/helper'; | ||
import { expect, test } from 'vitest'; | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
test('autoExtension generate .mjs in build artifacts with esm format when type is commonjs', async () => { | ||
const fixturePath = join(__dirname, 'type-commonjs'); | ||
const { entryFiles } = await buildAndGetResults(fixturePath); | ||
expect(extname(entryFiles.esm!)).toEqual('.mjs'); | ||
expect(extname(entryFiles.cjs!)).toEqual('.js'); | ||
describe('autoExtension: true', () => { | ||
test('generate .mjs in build artifacts with esm format when type is commonjs', async () => { | ||
const fixturePath = join(__dirname, 'type-commonjs'); | ||
const { entryFiles } = await buildAndGetResults(fixturePath); | ||
expect(extname(entryFiles.esm!)).toEqual('.mjs'); | ||
expect(extname(entryFiles.cjs!)).toEqual('.js'); | ||
}); | ||
|
||
test('generate .cjs in build artifacts with cjs format when type is module', async () => { | ||
const fixturePath = join(__dirname, 'type-module'); | ||
const { entryFiles } = await buildAndGetResults(fixturePath); | ||
expect(extname(entryFiles.esm!)).toEqual('.js'); | ||
expect(extname(entryFiles.cjs!)).toEqual('.cjs'); | ||
}); | ||
}); | ||
|
||
test('autoExtension generate .cjs in build artifacts with cjs format when type is module', async () => { | ||
const fixturePath = join(__dirname, 'type-module'); | ||
const { entryFiles } = await buildAndGetResults(fixturePath); | ||
expect(extname(entryFiles.esm!)).toEqual('.js'); | ||
expect(extname(entryFiles.cjs!)).toEqual('.cjs'); | ||
describe('autoExtension: false', () => { | ||
test('generate .js in both cjs and esm build artifacts when type is commonjs', async () => { | ||
const fixturePath = join(__dirname, 'type-commonjs'); | ||
const { entryFiles } = await buildAndGetResults( | ||
fixturePath, | ||
'autoExtension.false.config.ts', | ||
); | ||
expect(extname(entryFiles.esm!)).toEqual('.js'); | ||
expect(extname(entryFiles.cjs!)).toEqual('.js'); | ||
}); | ||
|
||
test('generate .js in both cjs and esm build artifacts when type is module', async () => { | ||
const fixturePath = join(__dirname, 'type-module'); | ||
const { entryFiles } = await buildAndGetResults( | ||
fixturePath, | ||
'autoExtension.false.config.ts', | ||
); | ||
expect(extname(entryFiles.esm!)).toEqual('.js'); | ||
expect(extname(entryFiles.cjs!)).toEqual('.js'); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
e2e/cases/autoExtension/type-commonjs/autoExtension.false.config.ts
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,18 @@ | ||
import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper'; | ||
import { defineConfig } from '@rslib/core'; | ||
|
||
export default defineConfig({ | ||
lib: [ | ||
generateBundleEsmConfig(__dirname, { | ||
autoExtension: false, | ||
}), | ||
generateBundleCjsConfig(__dirname, { | ||
autoExtension: false, | ||
}), | ||
], | ||
source: { | ||
entry: { | ||
main: './src/index.ts', | ||
}, | ||
}, | ||
}); |
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
18 changes: 18 additions & 0 deletions
18
e2e/cases/autoExtension/type-module/autoExtension.false.config.ts
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,18 @@ | ||
import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper'; | ||
import { defineConfig } from '@rslib/core'; | ||
|
||
export default defineConfig({ | ||
lib: [ | ||
generateBundleEsmConfig(__dirname, { | ||
autoExtension: false, | ||
}), | ||
generateBundleCjsConfig(__dirname, { | ||
autoExtension: false, | ||
}), | ||
], | ||
source: { | ||
entry: { | ||
main: './src/index.ts', | ||
}, | ||
}, | ||
}); |
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