Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create definition files into provided folder #182

Merged
merged 3 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/__tests__/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ test('hasLocalConfiguration returns true if a local config found and it is empty
expect(require('../utils').hasLocalConfig('module')).toBe(true)
})

test('should generate typescript definitions into provided folder', () => {
whichSyncMock.mockImplementationOnce(() => require.resolve('../'))
const {sync: crossSpawnSyncMock} = require('cross-spawn')
require('../utils').generateTypeDefs('destination folder')
expect(crossSpawnSyncMock).toHaveBeenCalledTimes(1)
const args = crossSpawnSyncMock.mock.calls[0][1]
const outDirIndex = args.findIndex(arg => arg === '--outDir') + 1

expect(args[outDirIndex]).toBe('destination folder')
})

function mockPkg({package: pkg = {}, path = '/blah/package.json'}) {
readPkgUpSyncMock.mockImplementationOnce(() => ({packageJson: pkg, path}))
}
Expand Down
5 changes: 3 additions & 2 deletions src/scripts/build/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,16 @@ function go() {
)
if (result.status !== 0) return result.status

const pathToOutDir = fromRoot(parsedArgs.outDir || builtInOutDir)

if (hasTypescript && !args.includes('--no-ts-defs')) {
console.log('Generating TypeScript definitions')
result = generateTypeDefs()
result = generateTypeDefs(pathToOutDir)
console.log('TypeScript definitions generated')
if (result.status !== 0) return result.status
}

// because babel will copy even ignored files, we need to remove the ignored files
const pathToOutDir = fromRoot(parsedArgs.outDir || builtInOutDir)
const ignoredPatterns = (parsedArgs.ignore || builtInIgnore)
.split(',')
.map(pattern => path.join(pathToOutDir, pattern))
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/build/rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function go() {

if (hasTypescript && !args.includes('--no-ts-defs')) {
console.log('Generating TypeScript definitions')
result = generateTypeDefs()
result = generateTypeDefs(fromRoot('dist'))
if (result.status !== 0) return result.status

for (const format of formats) {
Expand Down
4 changes: 2 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ function hasLocalConfig(moduleName, searchOptions = {}) {
return result !== null
}

function generateTypeDefs() {
function generateTypeDefs(outputDir) {
return spawn.sync(
resolveBin('typescript', {executable: 'tsc'}),
// prettier-ignore
[
'--declaration',
'--emitDeclarationOnly',
'--noEmit', 'false',
'--outDir', fromRoot('dist'),
'--outDir', outputDir,
],
{stdio: 'inherit'},
)
Expand Down