From a1949cb0ac49ca4bc80c311fd6a8e78ea1b78907 Mon Sep 17 00:00:00 2001 From: patrick Date: Tue, 19 Dec 2023 16:38:52 +0100 Subject: [PATCH] fix vite build --- packages/vite/src/hbs.ts | 8 +++++++- packages/vite/src/resolver.ts | 2 +- packages/vite/src/template-tag.ts | 9 ++++++++- pnpm-lock.yaml | 28 ++++++++++++++++++++++++++++ tests/scenarios/vite-app-test.ts | 11 +++++++++++ tests/vite-app/package.json | 1 + tests/vite-app/vite.config.mjs | 7 +++++++ 7 files changed, 63 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/hbs.ts b/packages/vite/src/hbs.ts index 3032bc713d..2d00c01462 100644 --- a/packages/vite/src/hbs.ts +++ b/packages/vite/src/hbs.ts @@ -14,9 +14,15 @@ export function hbs(): Plugin { return { name: 'rollup-hbs-plugin', enforce: 'pre', - async resolveId(source: string, importer: string | undefined) { + async resolveId(source: string, importer: string | undefined, options) { + if (options.custom?.onlyResolver) { + return null; + } let resolution = await this.resolve(source, importer, { skipSelf: true, + custom: { + onlyResolver: true, + }, }); if (!resolution) { diff --git a/packages/vite/src/resolver.ts b/packages/vite/src/resolver.ts index ccb7968591..f73c895e85 100644 --- a/packages/vite/src/resolver.ts +++ b/packages/vite/src/resolver.ts @@ -55,7 +55,7 @@ export function resolver(): Plugin { if (id.startsWith(virtualPrefix)) { let { src, watches } = virtualContent(id.slice(virtualPrefix.length), resolverLoader.resolver); virtualDeps.set(id, watches); - server.watcher.add(watches); + server?.watcher.add(watches); return src; } }, diff --git a/packages/vite/src/template-tag.ts b/packages/vite/src/template-tag.ts index 3cf210aa8f..115c9e7398 100644 --- a/packages/vite/src/template-tag.ts +++ b/packages/vite/src/template-tag.ts @@ -15,9 +15,15 @@ export function templateTag({ inline_source_map } = { inline_source_map: false } name: 'embroider-template-tag', enforce: 'pre', - async resolveId(id: string, importer: string | undefined) { + async resolveId(id: string, importer: string | undefined, options) { + if (options.custom?.onlyResolver) { + return null; + } let resolution = await this.resolve(id, importer, { skipSelf: true, + custom: { + onlyResolver: true, + }, }); if (resolution) { return resolution; @@ -26,6 +32,7 @@ export function templateTag({ inline_source_map } = { inline_source_map: false } resolution = await this.resolve(candidate, importer, { skipSelf: true, custom: { + onlyResolver: true, embroider: { enableCustomResolver: false, }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7769050a53..5a74b73e48 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1943,6 +1943,9 @@ importers: '@rollup/plugin-babel': specifier: ^5.3.1 version: 5.3.1(@babel/core@7.23.9)(rollup@3.29.4) + '@rollup/plugin-node-resolve': + specifier: ^15.2.3 + version: 15.2.3 broccoli-asset-rev: specifier: ^3.0.0 version: 3.0.0 @@ -6777,6 +6780,23 @@ packages: rollup: 3.29.4 dev: true + /@rollup/plugin-node-resolve@15.2.3: + resolution: {integrity: sha512-j/lym8nf5E21LwBT4Df1VD6hRO2L2iwUeUmP7litikRsVp1H6NWx20NEp0Y7su+7XGc476GnXXc4kFeZNGmaSQ==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^2.78.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + dependencies: + '@rollup/pluginutils': 5.1.0(rollup@3.29.4) + '@types/resolve': 1.20.2 + deepmerge: 4.3.1 + is-builtin-module: 3.2.1 + is-module: 1.0.0 + resolve: 1.22.8 + dev: true + /@rollup/plugin-typescript@11.1.6(rollup@3.29.4)(tslib@2.6.2)(typescript@5.2.2): resolution: {integrity: sha512-R92yOmIACgYdJ7dJ97p4K69I8gg6IEHt8M7dUBxN3W6nrO8uUxX5ixl0yU/N3aZTi8WhPuICvOHXQvF6FaykAA==} engines: {node: '>=14.0.0'} @@ -7317,6 +7337,10 @@ packages: /@types/range-parser@1.2.7: resolution: {integrity: sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==} + /@types/resolve@1.20.2: + resolution: {integrity: sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==} + dev: true + /@types/resolve@1.20.6: resolution: {integrity: sha512-A4STmOXPhMUtHH+S6ymgE2GiBSMqf4oTvcQZMcHzokuTLVYzXTB8ttjcgxOVaAp2lGwEdzZ0J+cRbbeevQj1UQ==} dev: true @@ -17285,6 +17309,10 @@ packages: '@babel/runtime': 7.23.9 dev: true + /is-module@1.0.0: + resolution: {integrity: sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==} + dev: true + /is-negative-zero@2.0.2: resolution: {integrity: sha512-dqJvarLawXsFbNDeJW7zAz8ItJ9cd28YufuuFzh0G8pNHjJMnY08Dv7sYX2uF5UpQOwieAeOExEYAWWfu7ZZUA==} engines: {node: '>= 0.4'} diff --git a/tests/scenarios/vite-app-test.ts b/tests/scenarios/vite-app-test.ts index 6f67e525ce..0943035564 100644 --- a/tests/scenarios/vite-app-test.ts +++ b/tests/scenarios/vite-app-test.ts @@ -112,5 +112,16 @@ viteAppScenarios const depCache = readdirSync(join(app.dir, 'node_modules', '.vite', 'deps')); assert.ok(depCache.length > 0, 'should have created cached deps'); }); + + test(`pnpm build`, async function (assert) { + let result = await app.execute('pnpm build'); + assert.equal(result.exitCode, 0, result.output); + const distFiles = readdirSync(join(app.dir, 'dist')); + assert.ok(distFiles.length > 1, 'should have created dist folder'); + assert.ok(distFiles.includes('assets'), 'should have created assets folder'); + + const assetFiles = readdirSync(join(app.dir, 'dist', 'assets')); + assert.ok(assetFiles.length > 1, 'should have created asset files'); + }); }); }); diff --git a/tests/vite-app/package.json b/tests/vite-app/package.json index b3493f3919..183d565ff1 100644 --- a/tests/vite-app/package.json +++ b/tests/vite-app/package.json @@ -38,6 +38,7 @@ "@glimmer/component": "^1.1.2", "@glimmer/tracking": "^1.1.2", "@rollup/plugin-babel": "^5.3.1", + "@rollup/plugin-node-resolve": "^15.2.3", "broccoli-asset-rev": "^3.0.0", "concurrently": "^8.2.0", "ember-auto-import": "^2.6.3", diff --git a/tests/vite-app/vite.config.mjs b/tests/vite-app/vite.config.mjs index 865a9f4bc2..a9e666d93f 100644 --- a/tests/vite-app/vite.config.mjs +++ b/tests/vite-app/vite.config.mjs @@ -8,6 +8,7 @@ import { compatPrebuild, } from "@embroider/vite"; import { resolve } from "path"; +import rollupResolve from "@rollup/plugin-node-resolve"; import { babel } from "@rollup/plugin-babel"; const root = "node_modules/.embroider/rewritten-app"; @@ -42,7 +43,13 @@ export default defineConfig({ }, }, build: { + outDir: resolve(process.cwd(), "dist"), rollupOptions: { + plugins: [ + rollupResolve({ + extensions: [".gjs", ".js", ".hbs", ".ts", ".gts"], + }), + ], input: { main: resolve(root, "index.html"), tests: resolve(root, "tests/index.html"),