-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Hiroki Osame <[email protected]>
- Loading branch information
1 parent
e526ba6
commit 0c20132
Showing
5 changed files
with
143 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import fs from 'fs'; | ||
import { fsExists } from './fs-exists.js'; | ||
|
||
export const cleanDist = async (directoryPath: string) => { | ||
const exists = await fsExists(directoryPath); | ||
if (!exists) { | ||
return; | ||
} | ||
|
||
await fs.promises.rm(directoryPath, { | ||
recursive: true, | ||
force: true, | ||
}); | ||
}; |
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,105 @@ | ||
import path from 'path'; | ||
import fs from 'fs/promises'; | ||
import { testSuite, expect } from 'manten'; | ||
import { createFixture } from 'fs-fixture'; | ||
import { pkgroll, installTypeScript } from '../../utils.js'; | ||
|
||
export default testSuite(({ describe }, nodePath: string) => { | ||
describe('clean dist', ({ test }) => { | ||
test('no flag', async ({ onTestFinish }) => { | ||
const fixture = await createFixture('./tests/fixture-package'); | ||
onTestFinish(async () => await fixture.rm()); | ||
|
||
installTypeScript(fixture.path); | ||
|
||
await fixture.writeJson('package.json', { | ||
main: './dist/nested/index.js', | ||
module: './dist/nested/index.mjs', | ||
types: './dist/nested/index.d.ts', | ||
}); | ||
|
||
await pkgroll( | ||
[], | ||
{ | ||
cwd: fixture.path, | ||
nodePath, | ||
}, | ||
); | ||
|
||
await fs.mkdir(path.join(fixture.path, 'src', 'nested2')); | ||
await fixture.writeFile('./src/nested2/index.ts', 'export function sayHello2(name: string) { return name; }'); | ||
|
||
await fixture.writeJson('package.json', { | ||
main: './dist/nested2/index.js', | ||
module: './dist/nested2/index.mjs', | ||
types: './dist/nested2/index.d.ts', | ||
}); | ||
|
||
const pkgrollProcess = await pkgroll( | ||
[], | ||
{ | ||
cwd: fixture.path, | ||
nodePath, | ||
}, | ||
); | ||
|
||
expect(pkgrollProcess.exitCode).toBe(0); | ||
expect(pkgrollProcess.stderr).toBe(''); | ||
|
||
expect(await fixture.exists('dist/nested/index.js')).toBe(true); | ||
expect(await fixture.exists('dist/nested/index.mjs')).toBe(true); | ||
expect(await fixture.exists('dist/nested/index.d.ts')).toBe(true); | ||
expect(await fixture.exists('dist/nested2/index.js')).toBe(true); | ||
expect(await fixture.exists('dist/nested2/index.mjs')).toBe(true); | ||
expect(await fixture.exists('dist/nested2/index.d.ts')).toBe(true); | ||
}); | ||
|
||
test('with flag', async ({ onTestFinish }) => { | ||
const fixture = await createFixture('./tests/fixture-package'); | ||
onTestFinish(async () => await fixture.rm()); | ||
|
||
installTypeScript(fixture.path); | ||
|
||
await fixture.writeJson('package.json', { | ||
main: './dist/nested/index.js', | ||
module: './dist/nested/index.mjs', | ||
types: './dist/nested/index.d.ts', | ||
}); | ||
|
||
await pkgroll( | ||
[], | ||
{ | ||
cwd: fixture.path, | ||
nodePath, | ||
}, | ||
); | ||
|
||
await fs.mkdir(path.join(fixture.path, 'src', 'nested2')); | ||
await fixture.writeFile('./src/nested2/index.ts', 'export function sayHello2(name: string) { return name; }'); | ||
|
||
await fixture.writeJson('package.json', { | ||
main: './dist/nested2/index.js', | ||
module: './dist/nested2/index.mjs', | ||
types: './dist/nested2/index.d.ts', | ||
}); | ||
|
||
const pkgrollProcess = await pkgroll( | ||
['--clean-dist'], | ||
{ | ||
cwd: fixture.path, | ||
nodePath, | ||
}, | ||
); | ||
|
||
expect(pkgrollProcess.exitCode).toBe(0); | ||
expect(pkgrollProcess.stderr).toBe(''); | ||
|
||
expect(await fixture.exists('dist/nested/index.js')).toBe(false); | ||
expect(await fixture.exists('dist/nested/index.mjs')).toBe(false); | ||
expect(await fixture.exists('dist/nested/index.d.ts')).toBe(false); | ||
expect(await fixture.exists('dist/nested2/index.js')).toBe(true); | ||
expect(await fixture.exists('dist/nested2/index.mjs')).toBe(true); | ||
expect(await fixture.exists('dist/nested2/index.d.ts')).toBe(true); | ||
}); | ||
}); | ||
}); |
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