-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(command): support --lib arguments (#390)
- Loading branch information
Showing
8 changed files
with
204 additions
and
55 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
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
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,54 @@ | ||
import { execSync } from 'node:child_process'; | ||
import path from 'node:path'; | ||
import fse from 'fs-extra'; | ||
import { globContentJSON } from 'test-helper'; | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
describe('build command', async () => { | ||
test('basic', async () => { | ||
await fse.remove(path.join(__dirname, 'dist')); | ||
execSync('npx rslib build', { | ||
cwd: __dirname, | ||
}); | ||
|
||
const files = await globContentJSON(path.join(__dirname, 'dist')); | ||
const fileNames = Object.keys(files).sort(); | ||
expect(fileNames).toMatchInlineSnapshot(` | ||
[ | ||
"<ROOT>/tests/integration/cli/dist/cjs/index.cjs", | ||
"<ROOT>/tests/integration/cli/dist/esm/index.js", | ||
] | ||
`); | ||
}); | ||
|
||
test('--lib', async () => { | ||
await fse.remove(path.join(__dirname, 'dist')); | ||
execSync('npx rslib build --lib esm', { | ||
cwd: __dirname, | ||
}); | ||
|
||
const files = await globContentJSON(path.join(__dirname, 'dist')); | ||
const fileNames = Object.keys(files).sort(); | ||
expect(fileNames).toMatchInlineSnapshot(` | ||
[ | ||
"<ROOT>/tests/integration/cli/dist/esm/index.js", | ||
] | ||
`); | ||
}); | ||
|
||
test('--lib multiple', async () => { | ||
await fse.remove(path.join(__dirname, 'dist')); | ||
execSync('npx rslib build --lib esm --lib cjs', { | ||
cwd: __dirname, | ||
}); | ||
|
||
const files = await globContentJSON(path.join(__dirname, 'dist')); | ||
const fileNames = Object.keys(files).sort(); | ||
expect(fileNames).toMatchInlineSnapshot(` | ||
[ | ||
"<ROOT>/tests/integration/cli/dist/cjs/index.cjs", | ||
"<ROOT>/tests/integration/cli/dist/esm/index.js", | ||
] | ||
`); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
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,95 @@ | ||
import { execSync } from 'node:child_process'; | ||
import path from 'node:path'; | ||
import { describe } from 'node:test'; | ||
import fse from 'fs-extra'; | ||
import { globContentJSON } from 'test-helper'; | ||
import { expect, test } from 'vitest'; | ||
|
||
describe('inspect command', async () => { | ||
test('basic', async () => { | ||
await fse.remove(path.join(__dirname, 'dist')); | ||
execSync('npx rslib inspect', { | ||
cwd: __dirname, | ||
}); | ||
|
||
const files = await globContentJSON(path.join(__dirname, 'dist/.rsbuild')); | ||
const fileNames = Object.keys(files).sort(); | ||
|
||
expect(fileNames).toMatchInlineSnapshot(` | ||
[ | ||
"<ROOT>/tests/integration/cli/dist/.rsbuild/rsbuild.config.cjs.mjs", | ||
"<ROOT>/tests/integration/cli/dist/.rsbuild/rsbuild.config.esm.mjs", | ||
"<ROOT>/tests/integration/cli/dist/.rsbuild/rspack.config.cjs.mjs", | ||
"<ROOT>/tests/integration/cli/dist/.rsbuild/rspack.config.esm.mjs", | ||
] | ||
`); | ||
|
||
// esm rsbuild config | ||
const rsbuildConfigEsm = fileNames.find((item) => | ||
item.includes('rsbuild.config.esm.mjs'), | ||
); | ||
expect(rsbuildConfigEsm).toBeTruthy(); | ||
expect(files[rsbuildConfigEsm!]).toContain("type: 'modern-module'"); | ||
|
||
// esm rspack config | ||
const rspackConfigEsm = fileNames.find((item) => | ||
item.includes('rspack.config.esm.mjs'), | ||
); | ||
expect(rspackConfigEsm).toBeTruthy(); | ||
expect(files[rspackConfigEsm!]).toContain("type: 'modern-module'"); | ||
}); | ||
|
||
test('--lib', async () => { | ||
await fse.remove(path.join(__dirname, 'dist')); | ||
execSync('npx rslib inspect --lib esm', { | ||
cwd: __dirname, | ||
}); | ||
|
||
const files = await globContentJSON( | ||
path.join(__dirname, 'dist/esm/.rsbuild'), | ||
); | ||
const fileNames = Object.keys(files).sort(); | ||
|
||
// Rsbuild will emit dump files to `dist/esm` if only one environment is specified. | ||
expect(fileNames).toMatchInlineSnapshot(` | ||
[ | ||
"<ROOT>/tests/integration/cli/dist/esm/.rsbuild/rsbuild.config.mjs", | ||
"<ROOT>/tests/integration/cli/dist/esm/.rsbuild/rspack.config.esm.mjs", | ||
] | ||
`); | ||
|
||
// esm rsbuild config | ||
const rsbuildConfigEsm = fileNames.find((item) => | ||
item.includes('rsbuild.config.mjs'), | ||
); | ||
expect(rsbuildConfigEsm).toBeTruthy(); | ||
expect(files[rsbuildConfigEsm!]).toContain("type: 'modern-module'"); | ||
|
||
// esm rspack config | ||
const rspackConfigEsm = fileNames.find((item) => | ||
item.includes('rspack.config.esm.mjs'), | ||
); | ||
expect(rspackConfigEsm).toBeTruthy(); | ||
expect(files[rspackConfigEsm!]).toContain("type: 'modern-module'"); | ||
}); | ||
|
||
test('--lib multiple', async () => { | ||
await fse.remove(path.join(__dirname, 'dist')); | ||
execSync('npx rslib inspect --lib esm --lib cjs', { | ||
cwd: __dirname, | ||
}); | ||
|
||
const files = await globContentJSON(path.join(__dirname, 'dist/.rsbuild')); | ||
const fileNames = Object.keys(files).sort(); | ||
|
||
// Rsbuild will emit dump files to `dist/esm` if only one environment is specified. | ||
expect(fileNames).toMatchInlineSnapshot(` | ||
[ | ||
"<ROOT>/tests/integration/cli/dist/.rsbuild/rsbuild.config.cjs.mjs", | ||
"<ROOT>/tests/integration/cli/dist/.rsbuild/rsbuild.config.esm.mjs", | ||
"<ROOT>/tests/integration/cli/dist/.rsbuild/rspack.config.cjs.mjs", | ||
"<ROOT>/tests/integration/cli/dist/.rsbuild/rspack.config.esm.mjs", | ||
] | ||
`); | ||
}); | ||
}); |
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 @@ | ||
export const foo = 'foo'; |
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