Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: outdir config not work #180

Merged
merged 6 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ vendors
.eslintcache
package-lock.json
.turbo
doc_build
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
## [0.7.30](https://github.com/sanyuan0704/island.js/compare/v0.7.28...v0.7.30) (2023-03-15)


### Bug Fixes

* fix template cli ([#167](https://github.com/sanyuan0704/island.js/issues/167)) ([2f2aa92](https://github.com/sanyuan0704/island.js/commit/2f2aa92574960ba73e7df340c2582baa00b7a068)), closes [#165](https://github.com/sanyuan0704/island.js/issues/165) [#165](https://github.com/sanyuan0704/island.js/issues/165) [#165](https://github.com/sanyuan0704/island.js/issues/165)



## [0.7.29](https://github.com/sanyuan0704/island.js/compare/v0.7.28...v0.7.29) (2023-03-15)


### Bug Fixes

* fix template cli ([#167](https://github.com/sanyuan0704/island.js/issues/167)) ([2f2aa92](https://github.com/sanyuan0704/island.js/commit/2f2aa92574960ba73e7df340c2582baa00b7a068)), closes [#165](https://github.com/sanyuan0704/island.js/issues/165) [#165](https://github.com/sanyuan0704/island.js/issues/165) [#165](https://github.com/sanyuan0704/island.js/issues/165)



## [0.7.29](https://github.com/sanyuan0704/island.js/compare/v0.7.28...v0.7.29) (2023-03-01)


### Bug Fixes

* fix template cli ([#167](https://github.com/sanyuan0704/island.js/issues/167)) ([2f2aa92](https://github.com/sanyuan0704/island.js/commit/2f2aa92574960ba73e7df340c2582baa00b7a068)), closes [#165](https://github.com/sanyuan0704/island.js/issues/165) [#165](https://github.com/sanyuan0704/island.js/issues/165) [#165](https://github.com/sanyuan0704/island.js/issues/165)



## [0.7.28](https://github.com/sanyuan0704/island.js/compare/v0.7.27...v0.7.28) (2023-03-01)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "islandjs-monorepo",
"private": true,
"version": "0.7.28",
"version": "0.7.30",
"description": "Vite & Islands architecture SSG framework",
"packageManager": "pnpm@7.9.2",
"type": "module",
Expand Down
6 changes: 4 additions & 2 deletions packages/create-island/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@islandjs/create-island",
"version": "0.7.28",
"version": "0.7.30",
"description": "create template for islandjs",
"packageManager": "pnpm@7.9.2",
"type": "module",
Expand Down Expand Up @@ -44,8 +44,10 @@
]
},
"devDependencies": {
"@types/prompts": "^2.4.2",
"@types/minimist": "^1.2.2",
"@types/prompts": "^2.4.2"
},
"dependencies": {
"execa": "5",
"kolorist": "^1.7.0",
"minimist": "^1.2.7",
Expand Down
6 changes: 3 additions & 3 deletions packages/island/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "islandjs",
"version": "0.7.28",
"version": "0.7.30",
"description": "Vite & Islands architecture SSG framework",
"packageManager": "pnpm@7.9.2",
"type": "module",
Expand Down Expand Up @@ -48,8 +48,8 @@
"@babel/core": "7.18.6",
"@babel/helper-plugin-utils": "7.18.6",
"@iconify-json/carbon": "1.1.8",
"@islandjs/plugin-backtop": "0.7.28",
"@islandjs/plugin-search": "0.7.28",
"@islandjs/plugin-backtop": "0.7.30",
"@islandjs/plugin-search": "0.7.30",
"@mdx-js/mdx": "2.1.3",
"@mdx-js/react": "2.1.3",
"@mdx-js/rollup": "2",
Expand Down
30 changes: 20 additions & 10 deletions packages/island/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { resolveConfig } from './config';
import {
CLIENT_ENTRY_PATH,
DEFAULT_EXTERNALS,
DIST_PATH,
DIST_DIR,
MASK_SPLITTER,
PUBLIC_DIR,
SERVER_ENTRY_PATH,
Expand All @@ -24,7 +24,7 @@ import {
VENDOR_PATH
} from './constants';
import { createVitePlugins } from './vitePlugin';
import { join, dirname } from 'path';
import path, { join, dirname } from 'path';
import { OutputAsset, OutputChunk, RollupOutput } from 'rollup';
import { createHash, dynamicImport } from './utils';
import { Route } from './plugin-routes';
Expand Down Expand Up @@ -65,12 +65,20 @@ class SSGBuilder {
#cliOptions: CLIBuildOption;
#clientBundle?: RollupOutput;
#serverBundle?: RollupOutput;
#distPath: string;
#islandsInjectCache: Map<string, Promise<string>> = new Map();

constructor(config: SiteConfig<unknown>, cliOptions: CLIBuildOption) {
this.#config = config;
this.#root = this.#config.root;
this.#cliOptions = cliOptions;
if (this.#config.outDir) {
this.#distPath = path.isAbsolute(this.#config.outDir)
? this.#config.outDir
: join(this.#root, DIST_DIR, this.#config.outDir);
} else {
this.#distPath = join(this.#root, DIST_DIR, 'dist');
}
}

async build() {
Expand All @@ -91,7 +99,7 @@ class SSGBuilder {
// Get complete css from server bundle
await copy(
join(TEMP_PATH, 'ssr', 'assets'),
join(this.#root, DIST_PATH, 'assets')
join(this.#distPath, 'assets')
);

await fs.writeFile(
Expand All @@ -102,7 +110,7 @@ class SSGBuilder {
// Copy public assets
const publicDirInRoot = join(this.#root, PUBLIC_DIR);
if (await pathExists(publicDirInRoot)) {
await copy(publicDirInRoot, join(this.#root, DIST_PATH));
await copy(publicDirInRoot, this.#distPath);
}

const serverEntryPath = join(SERVER_OUTPUT_PATH);
Expand All @@ -124,7 +132,7 @@ class SSGBuilder {
(chunk) => chunk.type === 'chunk' && chunk.isEntry
);
const clientChunkCode = await fs.readFile(
join(this.#root, DIST_PATH, clientEntryChunk!.fileName),
join(this.#distPath, clientEntryChunk!.fileName),
'utf-8'
);
// We get style from server bundle because it will generate complete css
Expand All @@ -145,7 +153,7 @@ class SSGBuilder {
);
await this.#render404Page(render, clientChunkInfo, styleAssets);
try {
await fs.copy(VENDOR_PATH, join(this.#root, DIST_PATH));
await fs.copy(VENDOR_PATH, this.#distPath);
} catch (e) {
console.log(e);
throw e;
Expand Down Expand Up @@ -239,7 +247,7 @@ class SSGBuilder {
// Move island_inject chunk
await copy(
join(TEMP_PATH, 'assets'),
join(this.#root, DIST_PATH, 'assets')
join(this.#distPath, 'assets')
);
} catch (e) {
// noop
Expand Down Expand Up @@ -342,8 +350,8 @@ class SSGBuilder {
return `${path}.html`.replace(normalizedBase, '');
};
const fileName = normalizeHtmlFilePath(routePath);
await fs.ensureDir(join(this.#root, DIST_PATH, dirname(fileName)));
await fs.writeFile(join(this.#root, DIST_PATH, fileName), html);
await fs.ensureDir(join(this.#distPath, dirname(fileName)));
await fs.writeFile(join(this.#distPath, fileName), html);
}

#render404Page(
Expand Down Expand Up @@ -393,7 +401,9 @@ class SSGBuilder {
build: {
minify: !process.env.NO_MINIFY && !isServer,
ssr: isServer,
outDir: isServer ? join(TEMP_PATH, 'ssr') : join(this.#root, DIST_PATH),
outDir: isServer
? join(TEMP_PATH, 'ssr')
: this.#distPath ?? join(this.#root, DIST_DIR),
cssCodeSplit: false,
ssrManifest: !isServer,
emptyOutDir: true,
Expand Down
5 changes: 2 additions & 3 deletions packages/island/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs-extra';
import path from 'path';
import pc from 'picocolors';
import { APPEARANCE_KEY } from '../shared/constants';
import { DEFAULT_THEME_PATH, DIST_PATH } from './constants';
import { DEFAULT_THEME_PATH } from './constants';
import {
DefaultTheme,
HeadConfig,
Expand Down Expand Up @@ -145,7 +145,6 @@ export async function resolveConfig(
customizeConfig
);
const srcDir = path.resolve(root, userConfig.srcDir || '');
const outDir = path.resolve(root, userConfig.outDir || DIST_PATH);
const userThemeDir = resolve(root, 'theme');
const themeDir = pathExistsSync(userThemeDir)
? userThemeDir
Expand All @@ -167,7 +166,7 @@ export async function resolveConfig(
const siteConfig: SiteConfig<DefaultTheme.Config> = {
root,
srcDir,
outDir,
outDir: userConfig.outDir,
themeDir,
configPath,
configDeps,
Expand Down
2 changes: 1 addition & 1 deletion packages/island/src/node/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const PUBLIC_DIR = 'public';

export const TEMP_PATH = join(PACKAGE_ROOT_PATH, 'node_modules', '.island');

export const DIST_PATH = join('.island', 'dist');
export const DIST_DIR = join('.island');

export const SERVER_BUNDLE_FILE = 'ssr-entry.mjs';

Expand Down
18 changes: 13 additions & 5 deletions packages/island/src/node/serve.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import fs from 'fs';
import path from 'path';
import path, { join } from 'path';
import sirv from 'sirv';
import compression from 'compression';
import polka from 'polka';
import { resolveConfig } from './config';
import { DIST_DIR } from './constants';

export interface CLIServeOption {
base?: string;
Expand All @@ -19,9 +20,16 @@ export async function serve(root: string, cliOptions: CLIServeOption) {
const config = await resolveConfig(root, 'serve', 'production');
const base = config.base?.replace(/^\//, '').replace(/\/$/, '') || '';
const notAnAsset = (pathname: string) => !pathname.includes('/assets/');
const notFoundPage = fs.readFileSync(
path.resolve(config.outDir!, './404.html')
);

let distPath = '';
if (config.outDir) {
distPath = path.isAbsolute(config.outDir)
? config.outDir
: join(config.root, DIST_DIR, config.outDir);
} else {
distPath = join(config.root, DIST_DIR, 'dist');
}
const notFoundPage = fs.readFileSync(path.resolve(distPath, './404.html'));
const onNoMatch: polka.Options['onNoMatch'] = (req, res) => {
res.statusCode = 404;
if (notAnAsset(req.path)) {
Expand All @@ -30,7 +38,7 @@ export async function serve(root: string, cliOptions: CLIServeOption) {
};

const compress = compression();
const serve = sirv(config.outDir, {
const serve = sirv(distPath, {
etag: true,
maxAge: 31536000,
immutable: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-backtop/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@islandjs/plugin-backtop",
"version": "0.7.28",
"version": "0.7.30",
"description": "Back top plugin for islandjs",
"packageManager": "pnpm@7.9.2",
"type": "module",
Expand Down Expand Up @@ -40,7 +40,7 @@
"react": "^18.2.0"
},
"peerDependencies": {
"islandjs": "0.7.28"
"islandjs": "0.7.30"
},
"files": [
"dist",
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-check-links/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@islandjs/plugin-check-links",
"version": "0.7.28",
"version": "0.7.30",
"description": "Dead links check plugin for islandjs",
"packageManager": "pnpm@7.9.2",
"type": "module",
Expand Down Expand Up @@ -40,7 +40,7 @@
"react": "^18.2.0"
},
"peerDependencies": {
"islandjs": "0.7.28"
"islandjs": "0.7.30"
},
"files": [
"dist",
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-search/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@islandjs/plugin-search",
"version": "0.7.28",
"version": "0.7.30",
"description": "Search plugin for islandjs",
"packageManager": "pnpm@7.9.2",
"type": "module",
Expand Down Expand Up @@ -40,7 +40,7 @@
"react": "^18.2.0"
},
"peerDependencies": {
"islandjs": "0.7.28"
"islandjs": "0.7.30"
},
"files": [
"dist",
Expand Down
16 changes: 7 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.