Alexandre-Fernandez / astro-i18n

A TypeScript-first internationalization library for Astro.
https://www.npmjs.com/package/astro-i18n
MIT License
249 stars 10 forks source link

`sync` command not working correctly #22

Closed js2me closed 1 year ago

js2me commented 1 year ago

Hello!

image

NodeJS: 18.14.0
OS: Windows 11 x64

package.json

{
  "name": "@example/basics",
  "type": "module",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "dev": "astro dev",
    "start": "astro dev",
    "build": "astro build",
    "preview": "astro preview",
    "astro": "astro",
    "i18n:sync": "astro-i18n sync"
  },
  "dependencies": {
    "astro": "^2.0.8",
    "astro-i18n":"^1.6.4"
  }
}

astro.config.mjs

import { defineConfig } from 'astro/config';
import i18n from "astro-i18n"

// https://astro.build/config
export default defineConfig({
    integrations: [i18n()]
});

Here is output of this command:

PS G:\projects\astro-test> npm run i18n:sync

> @example/basics@0.0.1 i18n:sync
> astro-i18n sync

G:\projects\astro-test\node_modules\astro-i18n\dist\src\cli\index.cjs:2
"use strict";var he=Object.create;var on=Object.defineProperty;var Te=Object.getOwnPropertyDescriptor;var xe=Object.getOwnPropertyNames;var $e=Object.getPrototypeOf,Ce=Object.prototype.hasOwnProperty;var Re=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of xe(t))!Ce.call(n,o)&&o!==e&&on(n,o,{get:()=>t[o],enumerable:!(r=Te(t,o))||r.enumerable});return n};var Ae=(n,t,e)=>(e=n!=null?he($e(n)):{},Re(t||!n||!n.__esModule?on(e,"default",{value:n,enumerable:!0}):e,n));var Nt=(n,t,e)=>{if(!t.has(n))throw TypeError("Cannot "+e)};var h=(n,t,e)=>(Nt(n,t,"read from private field"),e?e.call(n):t.get(n)),O=(n,t,e)=>{if(t.has(n))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(n):t.set(n,e)},W=(n,t,e,r)=>(Nt(n,t,"write to private field"),r?r.call(n,e):t.set(n,e),e);var Y=(n,t,e)=>(Nt(n,t,"access private method"),e);var St="default",sn="argv.main",j,at,an,ft,fn,Dt=class{constructor(t=[]){O(this,at);O(this,ft);this.command=St;this.args=[];this.options={};O(this,j,{});let[e,r]=process.argv;this.node=e??"",this.file=r??"",Y(this,at,an).call(this,t),Y(this,ft,fn).call(this,process.argv.slice(2),t.length===1&&t[0].name===St)}};j=new WeakMap,at=new WeakSet,an=function(t){for(let e of t){h(this,j)[e.name]||(h(this,j)[e.name]={});for(let r of e.options)h(this,j)[e.name][`--${r.name}`]=r.name,r.shortcut&&(h(this,j)[e.name][`-${r.shortcut}`]=r.name)}},ft=new WeakSet,fn=function(t,e=!1){var i;if(t.length===0)return;let r=t;e?this.command=St:(this.command=t.at(0),r=t.slice(1));let o=sn;for(let s of r){let a=h(this,j)[this.command][s];if(!a)s.startsWith("--")&&(a=s.replace("--","")),s.startsWith("-")&&(a=s.replace("-",""));else{this.options[a]=[],o=a;continue}if(o===sn){this.args.push(s);continue}(i=this.options[o])==null||i.push(s)}};function Ft(n=[]){return new Dt(n)}var ot=require("path");var x=require("fs"),F=require("path");function L(n){try{return JSON.parse((0,x.readFileSync)(n,"utf8"))}catch{return}}function q(n,t,e=[]){try{let r=(0,x.readdirSync)(n);for(let o=0;o<r.length;o+=1){let i=(0,F.join)(n,r[o]);e.some(s=>s.test(i))?(r.splice(o,1),o-=1):$(i,!1)&&q(i,t)}t(r,n)}catch{}}function $(n,t=!0){return t?(0,x.existsSync)(n)&&(0,x.lstatSync)(n).isDirectory():(0,x.lstatSync)(n).isDirectory()}function A(n,t=!0){return t?(0,x.existsSync)(n)&&!(0,x.lstatSync)(n).isDirectory():!(0,x.lstatSync)(n).isDirectory()}function H(...n){let t=(0,F.join)(...n);if(!(0,x.existsSync)(t))throw new ReferenceError(`Path: ${t} doesn't exist.`);return t}function Lt(n){return n.endsWith(F.sep)?n.slice(0,-1):n}function cn(n){return n.startsWith(F.sep)?n.slice(1):n}function p(n,t,e){let r=Lt(n).split(F.sep),o=r.pop()||"",i=r.join(F.sep);(0,x.mkdirSync)(i,{recursive:!0}),(0,x.writeFileSync)((0,F.join)(i,o),t,{encoding:"utf8",flag:e})}function un(n){let t=n.lastIndexOf(".");return t<0?[n,""]:[n.slice(0,t),n.slice(t+1)]}function k(n){let t=n.lastIndexOf(".");return t<0?"":n.slice(t+1).toLowerCase()}function ct(n){let t=n.lastIndexOf(".");return t<0?n:n.slice(0,t)}function pn(n){let t=n.lastIndexOf(".");return t<0?[n,""]:[n.slice(0,t),n.slice(t+1)]}function E(n){return Object.getPrototypeOf(n)===Object.prototype}function ut(n){return Array.isArray(n)&&n.every(t=>typeof t=="string")}function ln(n){if(!E(n))return!1;for(let t of Object.values(n))if(typeof t!="string")return!1;return!0}function gn(n){if(!E(n))throw new Error(`"${n}" is not of type Record<string, string>.`);for(let t of Object.values(n))if(typeof t!="string")throw new TypeError(`"${t}" is not of type string.`)}function _t(n,t){if(!n.includes(t))throw new Error(`${t} is not in [${n.join(", ")}].`)}function w(n){return Object.entries(n)}function pt(n){let t=typeof n;if(t==="bigint")return"number";if(t==="function")return"(...args: unknown[]) => unknown";if(t!=="object")return t;if(!n)return"null";if(Array.isArray(n))return n.length===0?"unknown[]":`(${[...new Set(n.map(r=>pt(r)))].join(" | ")})[]`;if(E(n)){let e=Object.entries(n).map(([r,o])=>`"${r}": ${pt(o)}`);return e.length===0?"Record<string, unknown>":`{ ${e.join(", ")} }`}return"unknown"}function mn(n,t,e){let r=n;for(let[o,i]of t.entries()){if(o===t.length-1){r[i]=e;break}if(!dn(r,i)){r[i]={},r=r[i];continue}if(Object.getPrototypeOf(r[i])===Object.prototype){r=r[i];continue}break}}function d(n,t,e){let{mode:r,modifyBase:o}={mode:"replace",modifyBase:!0,...e},i=o?n:jt(n);for(let[s,a]of w(t)){let f=i[s];if(dn(i,s)){E(f)&&E(a)?d(f,a):r==="replace"&&(i[s]=t[s]);continue}i[s]=t[s]}return i}function jt(n){return!n||typeof n!="object"?n:Array.isArray(n)?n.map(t=>typeof t=="object"?jt(t):t):w(n).reduce((t,[e,r])=>(t[e]=jt(r),t),{})}function dn(n,t){return Object.prototype.hasOwnProperty.call(n,t)}var l="astro.i18n.config",_=".astro",Z="i18n",B="{route}",C="astro-i18n",yn="tsconfig.json",lt=".",U=`.${C}`,gt="generated.d.ts",hn="generated.keys.json",Tn="env.d.ts",mt="astro.config",dt="i18n",xn="package.json",$n="deno.json",Cn="deno.jsonc",Rn=":",bt="|",An=",",En=":";function N(){return new Error("Cannot resolve astro's working directory.")}function S(n){return new Error(`Cannot resolve astro's working directory.

Error: Cannot resolve astro's working directory.
    at N (G:\projects\astro-test\node_modules\astro-i18n\dist\src\cli\index.cjs:2:5003)
    at Object.Hn [as sync] (G:\projects\astro-test\node_modules\astro-i18n\dist\src\cli\index.cjs:69:139)
    at Object.<anonymous> (G:\projects\astro-test\node_modules\astro-i18n\dist\src\cli\index.cjs:103:2276)
    at Module._compile (node:internal/modules/cjs/loader:1226:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1280:10)
    at Module.load (node:internal/modules/cjs/loader:1089:32)
    at Module._load (node:internal/modules/cjs/loader:930:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

I think I missed something from starting guide, anyway hope you helps!

js2me commented 1 year ago

Also, FYI, function t works correctly

FabianLars commented 1 year ago

One thing i did locally to resolve this was to replace all usages of process.env.PWD with process.cwd() in astro-i18n (the PWD env var does not exist on Windows).

I'm still hitting rollup errors afterwards when i'm actually trying to build the site (only on windows) but i'm not sure yet if astro-i18n causes that or something else. (fwiw the error does occur in a page generated by it)

Alexandre-Fernandez commented 1 year ago

Sorry for this, I do not have a windows machine to test this on. I made the necessary modifications like @FabianLars suggested, didn't know about that method. I'm closing this, try with astro-i18n@1.6.5, I'll reopen if you're still having problems.