-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(js): ignore tsx and .test. files with buildable swc libraries (#9540
) include update to simplify existing patterns ISSUES CLOSED: #9442 Co-authored-by: Caleb Ukle <caleb@Calebs-MBP-2.localdomain>
- Loading branch information
1 parent
f3e579a
commit 696fefd
Showing
5 changed files
with
176 additions
and
4 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
35 changes: 35 additions & 0 deletions
35
...ages/js/src/migrations/update-13-10-1/__snapshots__/update-lib-swcrc-exclude.spec.ts.snap
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,35 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Update .lib.swcrc exclude should update the exclude pattern 1`] = ` | ||
"{ | ||
\\"jsc\\": { | ||
\\"target\\": \\"es2017\\", | ||
\\"parser\\": { | ||
\\"syntax\\": \\"typescript\\", | ||
\\"decorators\\": true, | ||
\\"dynamicImport\\": true | ||
}, | ||
\\"transform\\": { | ||
\\"decoratorMetadata\\": true, | ||
\\"legacyDecorator\\": true | ||
}, | ||
\\"keepClassNames\\": true, | ||
\\"externalHelpers\\": true, | ||
\\"loose\\": true | ||
}, | ||
\\"module\\": { | ||
\\"type\\": \\"commonjs\\", | ||
\\"strict\\": true, | ||
\\"noInterop\\": true | ||
}, | ||
\\"sourceMaps\\": true, | ||
\\"exclude\\": [ | ||
\\".*.spec.tsx?$\\", | ||
\\".*.test.tsx?$\\", | ||
\\"./src/jest-setup.ts$\\", | ||
\\"./**/jest-setup.ts$\\", | ||
\\".*.js$\\" | ||
] | ||
} | ||
" | ||
`; |
90 changes: 90 additions & 0 deletions
90
packages/js/src/migrations/update-13-10-1/update-lib-swcrc-exclude.spec.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,90 @@ | ||
import { | ||
addProjectConfiguration, | ||
ProjectConfiguration, | ||
readJson, | ||
Tree, | ||
updateJson, | ||
} from '@nrwl/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; | ||
import updateSwcRcExclude from './update-lib-swcrc-exclude'; | ||
|
||
const projectConfig: ProjectConfiguration = { | ||
root: 'libs/swc-lib', | ||
sourceRoot: 'libs/swc-lib/src', | ||
targets: { | ||
build: { | ||
executor: '@nrwl/js:swc', | ||
outputs: ['{options.outputPath}'], | ||
options: { | ||
outputPath: 'dist/libs/swc-lib', | ||
main: 'libs/swc-lib/src/index.ts', | ||
tsConfig: 'libs/swc-lib/tsconfig.lib.json', | ||
assets: ['libs/swc-lib/*.md'], | ||
}, | ||
}, | ||
}, | ||
}; | ||
const oldSwcRc = { | ||
jsc: { | ||
target: 'es2017', | ||
parser: { | ||
syntax: 'typescript', | ||
decorators: true, | ||
dynamicImport: true, | ||
}, | ||
transform: { | ||
decoratorMetadata: true, | ||
legacyDecorator: true, | ||
}, | ||
keepClassNames: true, | ||
externalHelpers: true, | ||
loose: true, | ||
}, | ||
module: { | ||
type: 'commonjs', | ||
strict: true, | ||
noInterop: true, | ||
}, | ||
sourceMaps: true, | ||
exclude: [ | ||
'./src/**/.*.spec.ts$', | ||
'./**/.*.spec.ts$', | ||
'./src/**/jest-setup.ts$', | ||
'./**/jest-setup.ts$', | ||
'./**/.*.js$', | ||
], | ||
}; | ||
describe('Update .lib.swcrc exclude', () => { | ||
let tree: Tree; | ||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
addProjectConfiguration(tree, 'swc-lib', projectConfig); | ||
|
||
tree.write('libs/swc-lib/.lib.swcrc', JSON.stringify(oldSwcRc)); | ||
}); | ||
|
||
it('should update the exclude pattern', () => { | ||
updateSwcRcExclude(tree); | ||
expect(tree.read('libs/swc-lib/.lib.swcrc', 'utf-8')).toMatchSnapshot(); | ||
}); | ||
|
||
it('should NOT update the exclude pattern if not present', () => { | ||
updateJson(tree, 'libs/swc-lib/.lib.swcrc', (json) => { | ||
delete json.exclude; | ||
return json; | ||
}); | ||
|
||
const before = readJson(tree, 'libs/swc-lib/.lib.swcrc'); | ||
updateSwcRcExclude(tree); | ||
const after = readJson(tree, 'libs/swc-lib/.lib.swcrc'); | ||
|
||
expect(after.exclude).toBeFalsy(); | ||
expect(after).toEqual(before); | ||
}); | ||
|
||
it('should do nothing if .lib.swcrc doest not exist', () => { | ||
tree.delete('libs/swc-lib/.lib-swcrc'); | ||
|
||
expect(() => updateSwcRcExclude(tree)).not.toThrowError(); | ||
}); | ||
}); |
41 changes: 41 additions & 0 deletions
41
packages/js/src/migrations/update-13-10-1/update-lib-swcrc-exclude.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,41 @@ | ||
import { readProjectConfiguration, Tree, updateJson } from '@nrwl/devkit'; | ||
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils'; | ||
import { join } from 'path'; | ||
import { SwcExecutorOptions } from '../../utils/schema'; | ||
import { defaultExclude } from '../../utils/swc/add-swc-config'; | ||
|
||
export default function updateSwcRcExclude(tree: Tree) { | ||
forEachExecutorOptions( | ||
tree, | ||
'@nrwl/js:swc', | ||
(config: SwcExecutorOptions, projectName) => { | ||
const projectConfig = readProjectConfiguration(tree, projectName); | ||
const libSwcPath = join(projectConfig.root, '.lib.swcrc'); | ||
|
||
if (!tree.exists(libSwcPath)) return; | ||
|
||
updateJson( | ||
tree, | ||
libSwcPath, | ||
(json) => { | ||
if (json.exclude) { | ||
const excludePatterns = new Set([ | ||
...defaultExclude, | ||
...json.exclude, | ||
]); | ||
// remove old patterns that are duplicate for new patterns | ||
// defined in defaultExclude | ||
excludePatterns.delete('./**/.*.spec.ts$'); | ||
excludePatterns.delete('./src/**/.*.spec.ts$'); | ||
excludePatterns.delete('./**/.*.js$'); | ||
excludePatterns.delete('./src/**/jest-setup.ts$'); | ||
|
||
json.exclude = [...excludePatterns]; | ||
} | ||
return json; | ||
}, | ||
{ expectComments: 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