-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: validate build outputs against
package.json
(#33)
- Loading branch information
Showing
7 changed files
with
139 additions
and
122 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
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,30 @@ | ||
import { expect } from 'chai' | ||
import jiti from 'jiti' | ||
|
||
const { extractExportFilenames, inferExportType } = jiti(import.meta.url)('../src/utils') as typeof import('../src/utils') | ||
|
||
describe('inferExportType', () => { | ||
it('infers export type by condition', () => { | ||
expect(inferExportType('import')).to.equal('esm') | ||
expect(inferExportType('require')).to.equal('cjs') | ||
expect(inferExportType('node')).to.equal('esm') | ||
expect(inferExportType('some_unknown_condition')).to.equal('esm') | ||
}) | ||
it('infers export type based on previous conditions', () => { | ||
expect(inferExportType('import', ['require'])).to.equal('esm') | ||
expect(inferExportType('node', ['require'])).to.equal('cjs') | ||
expect(inferExportType('node', ['import'])).to.equal('esm') | ||
expect(inferExportType('node', ['unknown', 'require'])).to.equal('cjs') | ||
}) | ||
}) | ||
|
||
describe('extractExportFilenames', () => { | ||
it('handles strings', () => { | ||
expect(extractExportFilenames('test')).to.deep.equal([{ file: 'test', type: 'esm' }]) | ||
}) | ||
it('handles nested objects', () => { | ||
expect(extractExportFilenames({ require: 'test' })).to.deep.equal([{ file: 'test', type: 'cjs' }]) | ||
// @ts-ignore TODO: fix pkg-types | ||
expect(extractExportFilenames({ require: { node: 'test', other: { import: 'this', require: 'that' } } })).to.deep.equal([{ file: 'test', type: 'cjs' }, { file: 'this', type: 'esm' }, { file: 'that', type: 'cjs' }]) | ||
}) | ||
}) |
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,33 @@ | ||
import { fileURLToPath } from 'url' | ||
import jiti from 'jiti' | ||
import { expect } from 'chai' | ||
import consola from 'consola' | ||
import { join } from 'pathe' | ||
|
||
const { validatePackage } = jiti(import.meta.url)('../src/validate') as typeof import('../src/validate') | ||
|
||
describe('validatePackage', () => { | ||
it('detects missing files', () => { | ||
const logs: string[] = [] | ||
consola.mock(type => type === 'warn' ? (str: string) => logs.push(str) : () => {}) | ||
|
||
validatePackage({ | ||
main: './dist/test', | ||
bin: { | ||
'./cli': './dist/cli' | ||
}, | ||
module: 'dist/mod', | ||
exports: { | ||
'./runtime/*': './runtime/*.mjs', | ||
'.': { node: './src/index.ts' } | ||
} | ||
}, join(fileURLToPath(import.meta.url), '../fixture')) | ||
|
||
expect(logs[0]).to.include('Potential missing') | ||
expect(logs[0]).not.to.include('src/index.ts') | ||
|
||
for (const file of ['dist/test', 'dist/cli', 'dist/mod', 'runtime']) { | ||
expect(logs[0]).to.include(file) | ||
} | ||
}) | ||
}) |