-
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): update generated .swcrc file to align with @swc/[email protected]
- Loading branch information
Showing
8 changed files
with
138 additions
and
13 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
82 changes: 82 additions & 0 deletions
82
packages/js/src/migrations/update-16-8-2/update-swcrc.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,82 @@ | ||
import { addProjectConfiguration, readJson, Tree, writeJson } from '@nx/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import update from './update-swcrc'; | ||
|
||
describe('Migration: update .swcrc', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(async () => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
it('should remove invalid options for ES6 modules', async () => { | ||
addProjectConfiguration(tree, 'pkg', { | ||
root: 'pkg', | ||
}); | ||
writeJson(tree, 'pkg/.swcrc', { | ||
module: { | ||
type: 'es6', | ||
strict: true, | ||
noInterop: true, | ||
}, | ||
}); | ||
|
||
await update(tree); | ||
|
||
expect(readJson(tree, 'pkg/.swcrc')).toEqual({ | ||
module: { | ||
type: 'es6', | ||
}, | ||
}); | ||
}); | ||
|
||
it('should keep options for CommonJS modules', async () => { | ||
addProjectConfiguration(tree, 'pkg', { | ||
root: 'pkg', | ||
}); | ||
writeJson(tree, 'pkg/.swcrc', { | ||
module: { | ||
type: 'commonjs', | ||
strict: true, | ||
noInterop: true, | ||
}, | ||
}); | ||
|
||
await update(tree); | ||
|
||
expect(readJson(tree, 'pkg/.swcrc')).toEqual({ | ||
module: { | ||
type: 'commonjs', | ||
strict: true, | ||
noInterop: true, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should ignore projects without module options in .swcrc', async () => { | ||
addProjectConfiguration(tree, 'pkg', { | ||
root: 'pkg', | ||
}); | ||
writeJson(tree, 'pkg/.swcrc', { | ||
jsc: { | ||
target: 'es2017', | ||
}, | ||
}); | ||
|
||
await expect(update(tree)).resolves.not.toThrow(); | ||
|
||
expect(readJson(tree, 'pkg/.swcrc')).toEqual({ | ||
jsc: { | ||
target: 'es2017', | ||
}, | ||
}); | ||
}); | ||
|
||
it('should ignore projects without .swcrc', async () => { | ||
addProjectConfiguration(tree, 'pkg', { | ||
root: 'pkg', | ||
}); | ||
|
||
await expect(update(tree)).resolves.not.toThrow(); | ||
}); | ||
}); |
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 { | ||
formatFiles, | ||
getProjects, | ||
readJson, | ||
Tree, | ||
writeJson, | ||
} from '@nx/devkit'; | ||
import { join } from 'path'; | ||
|
||
export default async function update(tree: Tree) { | ||
const projects = getProjects(tree); | ||
|
||
for (const config of projects.values()) { | ||
const swcrcPath = join(config.root, '.swcrc'); | ||
if (!tree.exists(swcrcPath)) continue; | ||
const json = readJson(tree, swcrcPath); | ||
// No longer need strict or noInterop for es6 modules | ||
// See: https://github.com/swc-project/swc/commit/7e8d72d | ||
if ( | ||
json.module?.type === 'es6' && | ||
(json.module?.strict || json.module?.noInterop) | ||
) { | ||
delete json.module.noInterop; | ||
delete json.module.strict; | ||
writeJson(tree, swcrcPath, json); | ||
} | ||
} | ||
|
||
await formatFiles(tree); | ||
} |
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