From e0445b71e750285bb839e14f194fc1e79408eca4 Mon Sep 17 00:00:00 2001 From: caesar1shi Date: Tue, 26 Dec 2023 13:25:13 +0800 Subject: [PATCH 1/9] Windows adaptation: Fixed some error points in Windows systems --- packages/nuekit/src/cli.js | 3 ++- packages/nuekit/src/init.js | 9 ++++++--- packages/nuekit/src/nuekit.js | 4 ++-- packages/nuekit/src/site.js | 13 +++++++------ 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/packages/nuekit/src/cli.js b/packages/nuekit/src/cli.js index 06f75f9f..6b3eb500 100755 --- a/packages/nuekit/src/cli.js +++ b/packages/nuekit/src/cli.js @@ -65,7 +65,8 @@ export function getArgs(argv) { // read from package.json async function getVersion() { const { promises } = await import('fs') - const path = new URL('../package.json', import.meta.url).pathname + const pathname = new URL('../package.json', import.meta.url).pathname + const path = pathname.startsWith('/') ? pathname.slice(1) : pathname const json = await promises.readFile(path, 'utf-8') return JSON.parse(json).version } diff --git a/packages/nuekit/src/init.js b/packages/nuekit/src/init.js index 1863a0c0..63568886 100644 --- a/packages/nuekit/src/init.js +++ b/packages/nuekit/src/init.js @@ -10,7 +10,8 @@ export async function init({ dist, is_dev, esbuild }) { // directories const cwd = process.cwd() - const srcdir = new URL('.', import.meta.url).pathname + const pathname = new URL('.', import.meta.url).pathname + const srcdir = pathname.startsWith('/') ? pathname.slice(1) : pathname const fromdir = join(srcdir, 'browser') const outdir = join(cwd, dist, '@nue') const minify = !is_dev @@ -22,8 +23,10 @@ export async function init({ dist, is_dev, esbuild }) { return await fs.stat(latest) } catch { - await fs.rmdir(outdir, { recursive: true }) - await fs.mkdir(outdir) + try { + await fs.rm(outdir, { recursive: true }) + } catch {} + await fs.mkdir(outdir, { recursive: true }) await fs.writeFile(latest, '') } diff --git a/packages/nuekit/src/nuekit.js b/packages/nuekit/src/nuekit.js index b58d28e5..a7598d33 100644 --- a/packages/nuekit/src/nuekit.js +++ b/packages/nuekit/src/nuekit.js @@ -176,8 +176,8 @@ export async function createKit(args) { // else -> build() await buildJS({ - outdir: join(dist, file.dir), - path: join('.', root, path), + outdir: join(process.cwd(), dist, file.dir), + path: join(process.cwd(), root, path), minify: is_prod, bundle }) diff --git a/packages/nuekit/src/site.js b/packages/nuekit/src/site.js index 5bd27b44..efa716f7 100644 --- a/packages/nuekit/src/site.js +++ b/packages/nuekit/src/site.js @@ -9,6 +9,8 @@ import yaml from 'js-yaml' // file not found error code const NOT_FOUND = -2 +// file not found error code in windows +const ENOENT = -4058 export async function createSite(args) { @@ -38,7 +40,7 @@ export async function createSite(args) { const raw = await read(path) return yaml.load(raw) } catch (e) { - if (e.errno != NOT_FOUND) { + if (e.errno != NOT_FOUND && e.errno!= ENOENT) { throw `YAML parse error in ${path}` } else if (path == env) throw e } @@ -73,7 +75,6 @@ export async function createSite(args) { self.is_empty = true } - async function write(content, dir, filename) { const todir = join(dist, dir) @@ -84,7 +85,7 @@ export async function createSite(args) { return to } catch (e) { - if (e.errno != NOT_FOUND) throw e + if (e.errno != NOT_FOUND && e.errno!= ENOENT) throw e await fs.mkdir(todir, { recursive: true }) return await write(content, dir, filename) } @@ -99,7 +100,7 @@ export async function createSite(args) { !is_bulk && !self.is_empty && log(join(dir, base)) } catch (e) { - if (e.errno != NOT_FOUND) throw e + if (e.errno != NOT_FOUND && e.errno!= ENOENT) throw e await fs.mkdir(join(dist, dir), { recursive: true }) await copy(file) } @@ -127,7 +128,7 @@ export async function createSite(args) { }) } catch (e) { - if (e.errno != NOT_FOUND) return console.error(e) + if (e.errno != NOT_FOUND && e.errno!= ENOENT) return console.error(e) } } @@ -198,7 +199,7 @@ export async function createSite(args) { const html = await read(path) lib.push(...parseNue(html)) } catch (e) { - if (e.errno != NOT_FOUND) { + if (e.errno != NOT_FOUND && e.errno!= ENOENT) { log.error('parse error', path) console.error(e) } From 7dcf102c907cd015f611703c9df593d0c4d439ac Mon Sep 17 00:00:00 2001 From: caesarzztt Date: Thu, 4 Jan 2024 19:54:26 +0800 Subject: [PATCH 2/9] Update packages/nuekit/src/site.js Co-authored-by: nobkd <44443899+nobkd@users.noreply.github.com> --- packages/nuekit/src/site.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuekit/src/site.js b/packages/nuekit/src/site.js index efa716f7..5e54ea10 100644 --- a/packages/nuekit/src/site.js +++ b/packages/nuekit/src/site.js @@ -85,7 +85,7 @@ export async function createSite(args) { return to } catch (e) { - if (e.errno != NOT_FOUND && e.errno!= ENOENT) throw e + if (e.errno != NOT_FOUND && e.errno != ENOENT) throw e await fs.mkdir(todir, { recursive: true }) return await write(content, dir, filename) } From dcba13c24f6fa8a4cb8a3cd13e3503753ed8f85b Mon Sep 17 00:00:00 2001 From: caesarzztt Date: Thu, 4 Jan 2024 19:54:43 +0800 Subject: [PATCH 3/9] Update packages/nuekit/src/site.js Co-authored-by: nobkd <44443899+nobkd@users.noreply.github.com> --- packages/nuekit/src/site.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuekit/src/site.js b/packages/nuekit/src/site.js index 5e54ea10..4998f1ba 100644 --- a/packages/nuekit/src/site.js +++ b/packages/nuekit/src/site.js @@ -128,7 +128,7 @@ export async function createSite(args) { }) } catch (e) { - if (e.errno != NOT_FOUND && e.errno!= ENOENT) return console.error(e) + if (e.errno != NOT_FOUND && e.errno != ENOENT) return console.error(e) } } From bd69154db53ee9286672301d388283472f83c43a Mon Sep 17 00:00:00 2001 From: caesarzztt Date: Thu, 4 Jan 2024 20:05:45 +0800 Subject: [PATCH 4/9] Update init.js Add the 'force' option to the fs.rm command. --- packages/nuekit/src/init.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/nuekit/src/init.js b/packages/nuekit/src/init.js index dc209fc9..5c8fc31d 100644 --- a/packages/nuekit/src/init.js +++ b/packages/nuekit/src/init.js @@ -23,9 +23,7 @@ export async function init({ dist, is_dev, esbuild }) { return await fs.stat(latest) } catch { - try { - await fs.rm(outdir, { recursive: true }) - } catch {} + await fs.rm(outdir, { recursive: true, force: true }) await fs.mkdir(outdir, { recursive: true }) await fs.writeFile(latest, '') From 0283f10afd27807f0bc23187f95207f16269c109 Mon Sep 17 00:00:00 2001 From: caesarzztt Date: Thu, 4 Jan 2024 20:07:41 +0800 Subject: [PATCH 5/9] Update packages/nuekit/src/site.js Co-authored-by: nobkd <44443899+nobkd@users.noreply.github.com> --- packages/nuekit/src/site.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuekit/src/site.js b/packages/nuekit/src/site.js index 4998f1ba..de635544 100644 --- a/packages/nuekit/src/site.js +++ b/packages/nuekit/src/site.js @@ -100,7 +100,7 @@ export async function createSite(args) { !is_bulk && !self.is_empty && log(join(dir, base)) } catch (e) { - if (e.errno != NOT_FOUND && e.errno!= ENOENT) throw e + if (e.errno != NOT_FOUND && e.errno != ENOENT) throw e await fs.mkdir(join(dist, dir), { recursive: true }) await copy(file) } From 2808c997b2d5fb63cade1748e3fa7bbdb72f9af1 Mon Sep 17 00:00:00 2001 From: caesarzztt Date: Thu, 4 Jan 2024 20:07:50 +0800 Subject: [PATCH 6/9] Update packages/nuekit/src/site.js Co-authored-by: nobkd <44443899+nobkd@users.noreply.github.com> --- packages/nuekit/src/site.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuekit/src/site.js b/packages/nuekit/src/site.js index de635544..ef00e4c9 100644 --- a/packages/nuekit/src/site.js +++ b/packages/nuekit/src/site.js @@ -199,7 +199,7 @@ export async function createSite(args) { const html = await read(path) lib.push(...parseNue(html)) } catch (e) { - if (e.errno != NOT_FOUND && e.errno!= ENOENT) { + if (e.errno != NOT_FOUND && e.errno != ENOENT) { log.error('parse error', path) console.error(e) } From afdd872176201e1432c5eea42eac6480bca35648 Mon Sep 17 00:00:00 2001 From: caesarzztt Date: Thu, 4 Jan 2024 20:10:36 +0800 Subject: [PATCH 7/9] Update init.js --- packages/nuekit/src/init.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuekit/src/init.js b/packages/nuekit/src/init.js index 5c8fc31d..819cd9ea 100644 --- a/packages/nuekit/src/init.js +++ b/packages/nuekit/src/init.js @@ -11,7 +11,7 @@ export async function init({ dist, is_dev, esbuild }) { // directories const cwd = process.cwd() const pathname = new URL('.', import.meta.url).pathname - const srcdir = pathname.startsWith('/') ? pathname.slice(1) : pathname + const srcdir = process.platform === "win32" && pathname.startsWith('/') ? pathname.slice(1) : pathname const fromdir = join(srcdir, 'browser') const outdir = join(cwd, dist, '@nue') const minify = !is_dev From 0e5d6ec573ddecbae71330a21d9e966a2fce98af Mon Sep 17 00:00:00 2001 From: caesarzztt Date: Thu, 4 Jan 2024 20:11:17 +0800 Subject: [PATCH 8/9] Update cli.js --- packages/nuekit/src/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuekit/src/cli.js b/packages/nuekit/src/cli.js index 7e14ad2c..ca1e704b 100755 --- a/packages/nuekit/src/cli.js +++ b/packages/nuekit/src/cli.js @@ -66,7 +66,7 @@ export function getArgs(argv) { async function getVersion() { const { promises } = await import('fs') const pathname = new URL('../package.json', import.meta.url).pathname - const path = pathname.startsWith('/') ? pathname.slice(1) : pathname + const path = process.platform === "win32" && pathname.startsWith('/') ? pathname.slice(1) : pathname const json = await promises.readFile(path, 'utf-8') return JSON.parse(json).version } From c222fabefaf03033af732746a7ad218699fcbcdb Mon Sep 17 00:00:00 2001 From: caesarzztt Date: Thu, 4 Jan 2024 20:52:00 +0800 Subject: [PATCH 9/9] Update packages/nuekit/src/init.js Co-authored-by: nobkd <44443899+nobkd@users.noreply.github.com> --- packages/nuekit/src/init.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuekit/src/init.js b/packages/nuekit/src/init.js index 819cd9ea..33412ef7 100644 --- a/packages/nuekit/src/init.js +++ b/packages/nuekit/src/init.js @@ -11,7 +11,7 @@ export async function init({ dist, is_dev, esbuild }) { // directories const cwd = process.cwd() const pathname = new URL('.', import.meta.url).pathname - const srcdir = process.platform === "win32" && pathname.startsWith('/') ? pathname.slice(1) : pathname + const srcdir = process.platform === "win32" && pathname.startsWith('/') ? pathname.slice(1) : pathname const fromdir = join(srcdir, 'browser') const outdir = join(cwd, dist, '@nue') const minify = !is_dev