-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(qwik-nx): handle eslint checks in dev mode (#202)
- Loading branch information
1 parent
c5e0eda
commit ef60711
Showing
18 changed files
with
227 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,44 @@ | ||
import { | ||
ensureNxProject, | ||
listFiles, | ||
readJson, | ||
runNxCommandAsync, | ||
} from '@nx/plugin/testing'; | ||
import { DEFAULT_E2E_TIMEOUT } from '@qwikifiers/e2e/utils'; | ||
|
||
describe('appGenerator e2e', () => { | ||
// Setting up individual workspaces per | ||
// test can cause e2e runs to take a long time. | ||
// For this reason, we recommend each suite only | ||
// consumes 1 workspace. The tests should each operate | ||
// on a unique project in the workspace, such that they | ||
// are not dependant on one another. | ||
describe('misc checks', () => { | ||
beforeAll(() => { | ||
ensureNxProject('qwik-nx', 'dist/packages/qwik-nx'); | ||
}); | ||
|
||
afterAll(async () => { | ||
// `nx reset` kills the daemon, and performs | ||
// some work which can help clean up e2e leftovers | ||
await runNxCommandAsync('reset'); | ||
}); | ||
|
||
describe("qwik-nx's compiled package.json", () => { | ||
it( | ||
"qwik-nx's package.json should contain only expected dependencies", | ||
async () => { | ||
const packageJson = readJson('node_modules/qwik-nx/package.json'); | ||
it( | ||
"qwik-nx's package.json should contain only expected dependencies", | ||
async () => { | ||
const packageJson = readJson('node_modules/qwik-nx/package.json'); | ||
|
||
expect(packageJson.peerDependencies).toBeUndefined(); | ||
expect(packageJson.dependencies).toEqual({ | ||
'@nx/devkit': '^16.0.0', | ||
'@nx/js': '^16.0.0', | ||
'@nx/linter': '^16.0.0', | ||
'@nx/vite': '^16.0.0', | ||
}); | ||
}, | ||
DEFAULT_E2E_TIMEOUT | ||
); | ||
expect(packageJson.peerDependencies).toBeUndefined(); | ||
expect(packageJson.dependencies).toEqual({ | ||
'@nx/devkit': '^16.0.0', | ||
'@nx/js': '^16.0.0', | ||
'@nx/linter': '^16.0.0', | ||
'@nx/vite': '^16.0.0', | ||
}); | ||
}, | ||
DEFAULT_E2E_TIMEOUT | ||
); | ||
|
||
it('compiled output should contain all expected files', () => { | ||
const expectedFiles = [ | ||
'executors.json', | ||
'migrations.json', | ||
'generators.json', | ||
'README.md', | ||
]; | ||
const files = new Set(listFiles('node_modules/qwik-nx')); | ||
expect(expectedFiles.every((f) => files.has(f))); | ||
}); | ||
}); |
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
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
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
48 changes: 48 additions & 0 deletions
48
...qwik-vite-plugin/__snapshots__/set-proper-tsconfig-path-for-qwik-vite-plugin.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,48 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`set-proper-tsconfig-path-for-qwik-vite-plugin migration should add "tsconfigFileNames" property 1`] = ` | ||
"import { qwikVite } from \\"@builder.io/qwik/optimizer\\"; | ||
import { defineConfig } from \\"vite\\"; | ||
import tsconfigPaths from \\"vite-tsconfig-paths\\"; | ||
import { qwikNxVite } from \\"qwik-nx/plugins\\"; | ||
export default defineConfig({ | ||
plugins: [ | ||
qwikNxVite(), | ||
qwikVite({ | ||
tsconfigFileNames: [\\"tsconfig.app.json\\"], | ||
client: { | ||
outDir: \\"../../dist/apps/myapp/client\\", | ||
}, | ||
ssr: { | ||
outDir: \\"../../dist/apps/myapp/server\\", | ||
} | ||
}), | ||
tsconfigPaths({ root: \\"../../\\" }) | ||
] | ||
}); | ||
" | ||
`; | ||
|
||
exports[`set-proper-tsconfig-path-for-qwik-vite-plugin migration should not modify the "tsconfigFileNames" property if it exists 1`] = ` | ||
"import { qwikVite } from '@builder.io/qwik/optimizer'; | ||
import { defineConfig } from 'vite'; | ||
import tsconfigPaths from 'vite-tsconfig-paths'; | ||
import { qwikNxVite } from 'qwik-nx/plugins'; | ||
export default defineConfig({ | ||
plugins: [ | ||
qwikNxVite(), | ||
qwikVite({ | ||
client: { | ||
outDir: '../../dist/apps/myapp/client', | ||
}, | ||
ssr: { | ||
outDir: '../../dist/apps/myapp/server', | ||
}, | ||
tsconfigFileNames: [\\"MOCK_VALUE\\"] | ||
}), | ||
tsconfigPaths({ root: '../../' }), | ||
], | ||
}); | ||
" | ||
`; |
59 changes: 59 additions & 0 deletions
59
...-tsconfig-path-for-qwik-vite-plugin/set-proper-tsconfig-path-for-qwik-vite-plugin.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,59 @@ | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import { Tree } from '@nx/devkit'; | ||
|
||
import update from './set-proper-tsconfig-path-for-qwik-vite-plugin'; | ||
import appGenerator from '../../generators/application/generator'; | ||
|
||
describe('set-proper-tsconfig-path-for-qwik-vite-plugin migration', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(async () => { | ||
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); | ||
await appGenerator(tree, { name: 'myapp' }); | ||
}); | ||
|
||
it('should add "tsconfigFileNames" property', async () => { | ||
const viteConfigPath = `apps/myapp/vite.config.ts`; | ||
// just to ensure the file at that paths exists before updating it | ||
expect(tree.exists(viteConfigPath)).toBeTruthy(); | ||
|
||
tree.write(viteConfigPath, getViteConfigSample()); | ||
update(tree); | ||
expect(tree.read(viteConfigPath, 'utf-8')).toMatchSnapshot(); | ||
}); | ||
it('should not modify the "tsconfigFileNames" property if it exists', async () => { | ||
const viteConfigPath = `apps/myapp/vite.config.ts`; | ||
tree.write(viteConfigPath, getViteConfigSample(true)); | ||
|
||
update(tree); | ||
|
||
expect(tree.read(viteConfigPath, 'utf-8')).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
const getViteConfigSample = ( | ||
includeTSConfigFileNamesProp = false | ||
) => `import { qwikVite } from '@builder.io/qwik/optimizer'; | ||
import { defineConfig } from 'vite'; | ||
import tsconfigPaths from 'vite-tsconfig-paths'; | ||
import { qwikNxVite } from 'qwik-nx/plugins'; | ||
export default defineConfig({ | ||
plugins: [ | ||
qwikNxVite(), | ||
qwikVite({ | ||
client: { | ||
outDir: '../../dist/apps/myapp/client', | ||
}, | ||
ssr: { | ||
outDir: '../../dist/apps/myapp/server', | ||
},${ | ||
includeTSConfigFileNamesProp | ||
? '\ntsconfigFileNames: ["MOCK_VALUE"]' | ||
: '' | ||
} | ||
}), | ||
tsconfigPaths({ root: '../../' }), | ||
], | ||
}); | ||
`; |
34 changes: 34 additions & 0 deletions
34
...roper-tsconfig-path-for-qwik-vite-plugin/set-proper-tsconfig-path-for-qwik-vite-plugin.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,34 @@ | ||
import { Tree, getProjects } from '@nx/devkit'; | ||
import { isQwikNxProject } from '../../utils/migrations'; | ||
import { normalizeViteConfigFilePathWithTree } from '@nx/vite'; | ||
import { updateViteConfig } from '../../utils/update-vite-config'; | ||
|
||
export default function update(tree: Tree) { | ||
const projects = getProjects(tree); | ||
|
||
projects.forEach((config) => { | ||
if (isQwikNxProject(config)) { | ||
const viteConfigPath = normalizeViteConfigFilePathWithTree( | ||
tree, | ||
config.root | ||
); | ||
if (!viteConfigPath) { | ||
return; | ||
} | ||
const viteConfig = tree.read(viteConfigPath)!.toString(); | ||
|
||
if (viteConfig.includes('tsconfigFileNames')) { | ||
// dummy check to ensure viteConfig does not have "tsconfigFileNames" property | ||
// name collisions are very unlikely here so it seems fine to not run AST checks for this | ||
return; | ||
} | ||
|
||
const updated = updateViteConfig(viteConfig, { | ||
qwikViteConfig: { | ||
tsconfigFileNames: JSON.stringify(['tsconfig.app.json']), | ||
}, | ||
}); | ||
tree.write(viteConfigPath, updated); | ||
} | ||
}); | ||
} |
Oops, something went wrong.