diff --git a/packages/gatsby/migrations.json b/packages/gatsby/migrations.json new file mode 100644 index 0000000000..fdce6e3e04 --- /dev/null +++ b/packages/gatsby/migrations.json @@ -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" + } + } +} diff --git a/packages/gatsby/src/migrations/update-11-6-0/add-js-include-11-6-0.spec.ts b/packages/gatsby/src/migrations/update-11-6-0/add-js-include-11-6-0.spec.ts new file mode 100644 index 0000000000..7ca3eabd65 --- /dev/null +++ b/packages/gatsby/src/migrations/update-11-6-0/add-js-include-11-6-0.spec.ts @@ -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'], + }); + }); +}); diff --git a/packages/gatsby/src/migrations/update-11-6-0/add-js-include-11-6-0.ts b/packages/gatsby/src/migrations/update-11-6-0/add-js-include-11-6-0.ts new file mode 100644 index 0000000000..45998686ed --- /dev/null +++ b/packages/gatsby/src/migrations/update-11-6-0/add-js-include-11-6-0.ts @@ -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 = (value: T) => [...new Set(value)] as T; + +export default addJsInclude; diff --git a/packages/next/migrations.json b/packages/next/migrations.json index 954a080d65..c883aa55f4 100644 --- a/packages/next/migrations.json +++ b/packages/next/migrations.json @@ -36,6 +36,12 @@ "version": "11.5.0-beta.1", "description": "Remove tsconfig.app.json", "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": { diff --git a/packages/next/src/migrations/update-11-6-0/add-js-include-11-6-0.spec.ts b/packages/next/src/migrations/update-11-6-0/add-js-include-11-6-0.spec.ts new file mode 100644 index 0000000000..a9d71c980d --- /dev/null +++ b/packages/next/src/migrations/update-11-6-0/add-js-include-11-6-0.spec.ts @@ -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'], + }); + }); +}); diff --git a/packages/next/src/migrations/update-11-6-0/add-js-include-11-6-0.ts b/packages/next/src/migrations/update-11-6-0/add-js-include-11-6-0.ts new file mode 100644 index 0000000000..9ea787bf9b --- /dev/null +++ b/packages/next/src/migrations/update-11-6-0/add-js-include-11-6-0.ts @@ -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 = (value: T) => [...new Set(value)] as T; + +export default addJsInclude;