glyphix 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/glyphix.js +2 -0
  2. package/package.json +13 -10
package/glyphix.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ "use strict";var l=require("fs"),v=require("acorn"),o=require("path"),y=require("vite");var a="glyphix_virtual_import.js";var m=require("path");function f(u){return{name:"glyphix-resolve-id",resolveId(s){return s.startsWith("@system.")?{id:s,external:!0}:s.startsWith("/")?{id:`${u.rootPath}${s}`}:{id:s}},load(s){if(s===a)return u.virtualContent}}}function g(u){return{name:"generate-glyphix-bundle",generateBundle(s,i,t){for(let[e,r]of Object.entries(i))if(r.type==="chunk"&&(0,m.relative)(u.rootPath,r.facadeModuleId??"").includes(a)){delete i[e];return}}}}var I=require("crypto"),d=class{constructor(s){this.uxJsFiles=[];this.allEntries=[];this.thirdLibs=[];this.virtualImportContent="";this.rootPath="";this.uxJsFiles=s.source,this.rootPath=s.root}startBuild(){this.uxJsFiles=this.uxJsFiles.map(t=>(0,o.resolve)(this.rootPath,t)),this.uxJsFiles.map((t,e)=>{let r=`$${(0,I.randomUUID)().toString().replaceAll("-","")}`;return this.virtualImportContent+=`import ${r} from "${t}";`,r}).forEach(t=>{this.virtualImportContent+=`console.log(${t});`}),this.uxJsFiles.push(a),this.uxJsFiles.forEach(t=>{if(t===a){this.allEntries.push(t);return}let e=this.parseFileFilterImport(t),r=this.parseModuleEntry(t,e);this.allEntries.push(t),this.allEntries.push(...r)});let i=this.generateViteOption(this.allEntries);(0,y.build)(i)}parseFileFilterImport(s){let i=(0,l.readFileSync)(s).toString(),t=(0,v.parse)(i,{ecmaVersion:2020,sourceType:"module"});return!t||!t.body||!t.body.length?[]:t.body.map(r=>r.type==="ImportDeclaration"?r.source.value:"").filter(r=>r.length&&!r.startsWith("@system.")).map(r=>r.startsWith("/")?(0,o.resolve)(this.rootPath,r):r.startsWith(".")?(0,o.resolve)(s,"..",r):r)}parseModuleEntry(s,i){let t=[];return i.forEach(e=>{if(e===a)return;if(!e.includes("node_modules")&&e.startsWith("/")){t.push(`${this.rootPath}${e}`);return}if(e.startsWith(".")){t.push((0,o.resolve)(s,"..",e));return}let r=require.resolve(e),n=(0,o.dirname)(r);for(;!(0,l.existsSync)((0,o.resolve)(n,"package.json"));)if(n=(0,o.dirname)(n),n===process.cwd())throw Error(`not find module ${e}`);this.thirdLibs.push(e);let h=(0,o.resolve)(n,"package.json"),p=require(h);r=p.module||p.main}),t}generateViteOption(s){return{plugins:[f({rootPath:this.rootPath,virtualContent:this.virtualImportContent}),g({rootPath:this.rootPath})],build:{minify:!0,target:"node20",rollupOptions:{treeshake:!0,input:s,preserveEntrySignatures:"strict",output:{format:"es",dir:(0,o.resolve)(this.rootPath,".vite-dist"),entryFileNames:t=>{let e=(0,o.relative)(this.rootPath,t.facadeModuleId);return this.uxJsFiles.findIndex(r=>r.includes(e))>=0&&!e.startsWith(".")?e:"[name]-[hash].js"},chunkFileNames:t=>{let r=t.moduleIds[t.moduleIds.length-1].split("/"),n=t.name;return r.forEach((h,p)=>{h==="node_modules"&&(n=r[p+1])}),`${n}-[hash].js`},manualChunks:{vendor:this.thirdLibs}}},sourcemap:!1}}}},c=process.env.VITE_BUILD_DIR;if(!c)throw Error("not find env VITE_BUILD_DIR");var x=JSON.parse((0,l.readFileSync)((0,o.resolve)(c,"entry.vite.json")).toString()),P=new d({root:c,source:x.entry});P.startBuild();
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
- "name": "glyphix",
3
- "version": "1.0.0",
4
- "description": "The glyphix package tools.",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "gx"
8
- },
9
- "author": "",
10
- "license": "ISC"
11
- }
2
+ "name": "glyphix",
3
+ "version": "1.0.1",
4
+ "license": "MIT",
5
+ "main": "lib/index.js",
6
+ "bin": {
7
+ "glyphix": "./glyphix.js"
8
+ },
9
+ "dependencies": {
10
+ "acorn": "^8.14.0",
11
+ "rollup": "^3.10.0",
12
+ "vite": "^6.0.6"
13
+ }
14
+ }