Skip to content

Commit

Permalink
chore: only build views if we have at least one
Browse files Browse the repository at this point in the history
  • Loading branch information
joshamaju committed Dec 2, 2024
1 parent 21507af commit af66f61
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 48 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-experts-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stack54": patch
---

Fixes views build failure caused by when no view found in project directory
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "stack54-monorepo",
"version": "1.0.0",
"description": "",
"author": "Joshua Amaju",
"license": "ISC",
"private": true,
"keywords": [],
"repository": {
"type": "git",
"url": "https://github.com/joshamaju/stack54.git"
},
"scripts": {
"test": "pnpm test -r",
"changeset": "changeset",
"version": "changeset version",
"release": "changeset publish",
"build": "tsc -b tsconfig.build.json"
},
"devDependencies": {
"@changesets/cli": "^2.27.1",
"playwright": "^1.41.1",
"typescript": "^5.3.3"
}
}
100 changes: 52 additions & 48 deletions packages/core/src/core/build/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,56 +116,60 @@ export function buildViews({
// @ts-ignore build gets the filtered type wrong
const facades = new Map(facade_keypairs.filter((_) => _ !== undefined));

const resolve: Plugin = {
name: "facade-resolver",
async resolveId(source, importer) {
if (importer) {
const [importer_] = importer.split("?");

/**
* resolves imports (including import aliases) inside inline script and modules script tags
* i.e
* <script type="module">
* import module from '@/aliased/module'
* import module from './file/path'
* import module form 'installed/node-module'
* </script>
*/
if (facades.has(importer_)) {
// reconstruct the original svelte file name from the html facade
const original = importer_.replace(generated_dir, "");

const { dir, name } = path.parse(original);
const view = path.join(dir, `${name}.svelte`);

const resolved = await this.resolve(source, view);

if (resolved) return resolved;

const file = path.resolve(path.dirname(original), source);
if (await fse.exists(file)) return file;
if (facades.size > 0) {
const resolve: Plugin = {
name: "facade-resolver",
async resolveId(source, importer) {
if (importer) {
const [importer_] = importer.split("?");

/**
* resolves imports (including import aliases) inside inline script and modules script tags
* i.e
* <script type="module">
* import module from '@/aliased/module'
* import module from './file/path'
* import module form 'installed/node-module'
* </script>
*/
if (facades.has(importer_)) {
// reconstruct the original svelte file name from the html facade
const original = importer_.replace(generated_dir, "");

const { dir, name } = path.parse(original);
const view = path.join(dir, `${name}.svelte`);

const resolved = await this.resolve(source, view);

if (resolved) return resolved;

const file = path.resolve(path.dirname(original), source);
if (await fse.exists(file)) return file;
}
}
}
},
};

const env_define = define(env);

const inline_config: vite.InlineConfig = {
logLevel: "silent",
define: env_define,
mode: "production",
plugins: [resolve, obfuscate, deobfuscate],
build: {
ssr: false,
outDir: build_dir,
rollupOptions: { input: [...facades.keys()] },
},
};
},
};

const env_define = define(env);

const inline_config: vite.InlineConfig = {
logLevel: "silent",
define: env_define,
mode: "production",
plugins: [resolve, obfuscate, deobfuscate],
build: {
ssr: false,
outDir: build_dir,
rollupOptions: { input: [...facades.keys()] },
},
};

yield* Effect.tryPromise(() => {
return vite.build(vite.mergeConfig(config.vite, inline_config));
});
yield* Effect.tryPromise(() => {
return vite.build(vite.mergeConfig(config.vite, inline_config));
});
} else {
yield* Effect.logWarning("No views to build");
}

const modules = yield* Effect.forEach(
facades,
Expand Down

0 comments on commit af66f61

Please sign in to comment.