Tsconfig js migration (#4993)
* chore(gatsby): add migration to add js file patterns to tsconfig.app.json * chore(nextjs): add migration to add js file patterns to tsconfig
This commit is contained in:
parent
00516ecd68
commit
aba5c44ec1
10
packages/gatsby/migrations.json
Normal file
10
packages/gatsby/migrations.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"schematics": {
|
||||||
|
"add-js-include-11.6.0": {
|
||||||
|
"cli": "nx",
|
||||||
|
"version": "11.6.0-beta.0",
|
||||||
|
"description": "Add js patterns to tsconfig.app.json",
|
||||||
|
"factory": "./src/migrations/update-11-6-0/add-js-include-11-6-0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
import { readJson, Tree, writeJson } from '@nrwl/devkit';
|
||||||
|
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||||
|
import addJsInclude from './add-js-include-11-6-0';
|
||||||
|
|
||||||
|
describe('Add js include 11.6.0', () => {
|
||||||
|
let tree: Tree;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
tree = createTreeWithEmptyWorkspace();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add js patterns to tsconfig "include" and "exclude"', async () => {
|
||||||
|
writeJson(tree, 'workspace.json', {
|
||||||
|
projects: {
|
||||||
|
app1: {
|
||||||
|
root: 'apps/app1',
|
||||||
|
targets: {
|
||||||
|
build: {
|
||||||
|
executor: '@nrwl/gatsby:build',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
writeJson(tree, 'nx.json', {
|
||||||
|
projects: {
|
||||||
|
app1: {},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
writeJson(tree, 'apps/app1/tsconfig.app.json', {
|
||||||
|
include: ['**/*.ts'],
|
||||||
|
exclude: ['**/*.spec.tsx'],
|
||||||
|
});
|
||||||
|
|
||||||
|
await addJsInclude(tree);
|
||||||
|
|
||||||
|
expect(readJson(tree, 'apps/app1/tsconfig.app.json')).toMatchObject({
|
||||||
|
include: ['**/*.ts', '**/*.js', '**/*.jsx'],
|
||||||
|
exclude: ['**/*.spec.tsx', '**/*.spec.js', '**/*.spec.jsx'],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
import { getProjects, Tree, updateJson } from '@nrwl/devkit';
|
||||||
|
|
||||||
|
export async function addJsInclude(host: Tree) {
|
||||||
|
const projects = getProjects(host);
|
||||||
|
|
||||||
|
projects.forEach((project) => {
|
||||||
|
const tsconfigPath = `${project.root}/tsconfig.app.json`;
|
||||||
|
|
||||||
|
if (project.targets?.build?.executor !== '@nrwl/gatsby:build') return;
|
||||||
|
|
||||||
|
if (!host.exists(tsconfigPath)) return;
|
||||||
|
|
||||||
|
updateJson(host, tsconfigPath, (json) => {
|
||||||
|
if (!json.include) {
|
||||||
|
json.include = [];
|
||||||
|
}
|
||||||
|
if (!json.exclude) {
|
||||||
|
json.exclude = [];
|
||||||
|
}
|
||||||
|
json.include = uniq([...json.include, '**/*.js', '**/*.jsx']);
|
||||||
|
json.exclude = uniq([...json.exclude, '**/*.spec.js', '**/*.spec.jsx']);
|
||||||
|
return json;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const uniq = <T extends string[]>(value: T) => [...new Set(value)] as T;
|
||||||
|
|
||||||
|
export default addJsInclude;
|
||||||
@ -36,6 +36,12 @@
|
|||||||
"version": "11.5.0-beta.1",
|
"version": "11.5.0-beta.1",
|
||||||
"description": "Remove tsconfig.app.json",
|
"description": "Remove tsconfig.app.json",
|
||||||
"factory": "./src/migrations/update-11-5-0/remove-tsconfig-app-11-5-0"
|
"factory": "./src/migrations/update-11-5-0/remove-tsconfig-app-11-5-0"
|
||||||
|
},
|
||||||
|
"add-js-include-11.6.0": {
|
||||||
|
"cli": "nx",
|
||||||
|
"version": "11.6.0-beta.0",
|
||||||
|
"description": "Add js patterns to tsconfig.json",
|
||||||
|
"factory": "./src/migrations/update-11-6-0/add-js-include-11-6-0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"packageJsonUpdates": {
|
"packageJsonUpdates": {
|
||||||
|
|||||||
@ -0,0 +1,41 @@
|
|||||||
|
import { readJson, Tree, writeJson } from '@nrwl/devkit';
|
||||||
|
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||||
|
import addJsInclude from './add-js-include-11-6-0';
|
||||||
|
|
||||||
|
describe('Add js include 11.6.0', () => {
|
||||||
|
let tree: Tree;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
tree = createTreeWithEmptyWorkspace();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add js patterns to tsconfig "include"', async () => {
|
||||||
|
writeJson(tree, 'workspace.json', {
|
||||||
|
projects: {
|
||||||
|
app1: {
|
||||||
|
root: 'apps/app1',
|
||||||
|
targets: {
|
||||||
|
build: {
|
||||||
|
executor: '@nrwl/next:build',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
writeJson(tree, 'nx.json', {
|
||||||
|
projects: {
|
||||||
|
app1: {},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
writeJson(tree, 'apps/app1/tsconfig.json', {
|
||||||
|
include: ['**/*.ts'],
|
||||||
|
});
|
||||||
|
|
||||||
|
await addJsInclude(tree);
|
||||||
|
|
||||||
|
expect(readJson(tree, 'apps/app1/tsconfig.json')).toMatchObject({
|
||||||
|
include: ['**/*.ts', '**/*.js', '**/*.jsx'],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
import { getProjects, Tree, updateJson } from '@nrwl/devkit';
|
||||||
|
|
||||||
|
export async function addJsInclude(host: Tree) {
|
||||||
|
const projects = getProjects(host);
|
||||||
|
|
||||||
|
projects.forEach((project) => {
|
||||||
|
const tsconfigPath = `${project.root}/tsconfig.json`;
|
||||||
|
|
||||||
|
if (project.targets?.build?.executor !== '@nrwl/next:build') return;
|
||||||
|
|
||||||
|
if (!host.exists(tsconfigPath)) return;
|
||||||
|
|
||||||
|
updateJson(host, tsconfigPath, (json) => {
|
||||||
|
if (!json.include) {
|
||||||
|
json.include = [];
|
||||||
|
}
|
||||||
|
json.include = uniq([...json.include, '**/*.js', '**/*.jsx']);
|
||||||
|
return json;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const uniq = <T extends string[]>(value: T) => [...new Set(value)] as T;
|
||||||
|
|
||||||
|
export default addJsInclude;
|
||||||
Loading…
x
Reference in New Issue
Block a user