build-ts 3.1.2 → 3.1.3

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.
@@ -1,2 +1,2 @@
1
- import e from"yargs";import{hideBin as r}from"yargs/helpers";import o from"node:fs";import s from"node:path";import{babel as i}from"@rollup/plugin-babel";import n from"@rollup/plugin-commonjs";import t from"@rollup/plugin-json";import a from"@rollup/plugin-node-resolve";import p from"@rollup/plugin-replace";import c from"@rollup/plugin-terser";import l from"dotenv";import{rollup as m}from"rollup";import d from"rollup-plugin-analyzer";import{externals as u}from"rollup-plugin-node-externals";import{string as f}from"rollup-plugin-string";import g from"rollup-plugin-ts";import b from"node:url";import*as h from"node:child_process";const v={command:"build [package]",describe:"Build a package",builder:{target:{description:"A target format: app or lib",type:"string",require:!0,alias:"t"},input:{description:'A file path of main source code. Default value is "src/index.ts" from package directory.',type:"string",alias:"i"},firebase:{description:"A file path of firebase.json.",type:"string"},"core-js":{description:"Whether or not core-js is employed.",type:"boolean",default:!1},minify:{description:"Whether or not minification is enabled.",type:"boolean",default:!0},sourcemap:{description:"Whether or not sourcemap is enabled.",type:"boolean",default:!0},external:{description:"Additional external dependencies.",type:"array"},verbose:{description:"Whether or not verbose mode is enabled.",type:"boolean",alias:"v"},env:{description:"Environment variables to be inlined.",type:"array",alias:"e"},dotenv:{description:".env files to be inlined.",type:"array"}},async handler(e){"app"!==e.target&&"lib"!==e.target&&(console.error('target option must be "app" or "lib"'),process.exit(1));let r=e.package?.toString()??".";r.endsWith("package.json")||(r=s.resolve(r,"package.json"));const l=await o.promises.readFile(r,"utf8"),h=JSON.parse(l);h&&h.main||(console.error('Please add "main" property in package.json.'),process.exit(1));const v=h.main,x=s.dirname(r),w=e.input||s.join(x,"src","index.ts");let S=s.join(x,v);e.coreJs&&(process.env.BUILD_TS_COREJS="1"),e.verbose&&(process.env.BUILD_TS_VERBOSE="1"),process.env.BUILD_TS_TARGET=e.target;const[O,k]=function(e){const r=e.name?.toString()||"",o=/@([^/]+)\/(.+)/.exec(r),[,s,i]=o||[];return[s,i]}(h),_=function(e,r,o){const l=[...e.external??[]].map((e=>e.toString()));r?.dependencies?.["@prisma/client"]&&l.push("prisma-client");const m=[".cjs",".mjs",".js",".jsx",".json",".cts",".mts",".ts",".tsx"],h=s.join(b.fileURLToPath(s.dirname(s.dirname(import.meta.url))),"babel.config.mjs"),v=[p({delimiters:["",""],preventAssignment:!0,values:y(e)}),t(),u({deps:!0,devDeps:!1,include:l,exclude:o&&new RegExp(`${o}\\/.+`)}),a({extensions:m}),n()];"app"===e.target?v.push(i({configFile:h,extensions:m,babelHelpers:"bundled",exclude:"node_modules/**"})):v.push(g({transpiler:"babel",babelConfig:h}));v.push(f({include:["**/*.csv","**/*.txt"]})),e.minify&&v.push(c());return v.push(d({summaryOnly:!0})),v}(e,h,O),N="app"===e.target&&e.firebase&&o.existsSync(e.firebase);N&&(S=await async function(e,r,i,n){const t=await o.promises.readFile(e,"utf8"),a=JSON.parse(t),p=s.resolve(s.dirname(e),a.functions.source);return r=s.join(p,s.basename(n)),await o.promises.rm(p,{recursive:!0,force:!0}),await o.promises.mkdir(p,{recursive:!0}),i.name+="-dist",i.main=s.relative(p,r),delete i.devDependencies,await o.promises.writeFile(s.join(p,"package.json"),JSON.stringify(i)),r}(e.firebase,S,h,v));const A=function(e,r,o,i){const n=[];if("app"===e.target)n.push({file:r,format:".mjs"===s.extname(r)?"module":"commonjs",sourcemap:e.sourcemap});else{const r=[[o.main,".mjs"===s.extname(o.main??"")?"module":"commonjs"],[o.module,"module"]];for(const[o,t]of r)o&&n.push({dir:j(s.dirname(o),i),format:t,preserveModules:!0,sourcemap:e.sourcemap})}return n}(e,S,h,k);let E;process.chdir(x);let J=!1;try{const[e]=await Promise.all([m({input:w,plugins:_}),!N&&o.promises.rm(s.dirname(S),{recursive:!0,force:!0})]);await Promise.all(A.map((r=>e.write(r)))),E=e}catch(e){J=!0,console.error("Filed to build due to:",e)}await(E?.close()),J&&process.exit(1)}};function y(e){const r={};for(const o of(e.env??[]).map((e=>e.toString())))void 0!==process.env[o]&&(r[`process.env.${o}`]=JSON.stringify(process.env[o]));for(const o of e.dotenv??[]){const e=l.config({path:o.toString()}).parsed||{};for(const[o,s]of Object.entries(e))void 0!==s&&(r[`process.env.${o}`]=JSON.stringify(s))}return r}function j(e,r){if(!r)return e;const o=e.indexOf(r);return o<0?e:e.slice(0,o)}const x={command:"run <file>",describe:"Run script",builder:{module:{description:"A module type: cjs or esm",type:"string",alias:"m"},watch:{description:"Whether watch mode is enabled or not",type:"boolean",alias:"w"}},async handler(e){const r=e.file?.toString()||"",i=await async function(e,r){if("cjs"===r||e.endsWith(".cts"))return"cjs";if("esm"===r||e.endsWith(".mts"))return"esm";let i=s.dirname(e);for(;;){const e=s.join(i,"package.json");if(o.existsSync(e)){try{const r=await o.promises.readFile(e,"utf8");if("module"===JSON.parse(r).type)return"esm"}catch{}break}const r=s.dirname(i);if(!r||r===i)break;i=r}return"cjs"}(r,e.module),n=["--no-warnings"];e.watch&&n.push("--watch"),"cjs"===i?n.push("--require","ts-node/register"):n.push("--loader","ts-node/esm"),n.push(r),h.spawnSync("node",n,{shell:!0,stdio:"inherit",env:{...process.env,TS_NODE_TRANSPILE_ONLY:"1"}})}};await e(r(process.argv)).command(v).command(x).demandCommand().help().argv;
1
+ import e from"yargs";import{hideBin as r}from"yargs/helpers";import o from"node:fs";import s from"node:path";import{babel as i}from"@rollup/plugin-babel";import n from"@rollup/plugin-commonjs";import t from"@rollup/plugin-json";import a from"@rollup/plugin-node-resolve";import p from"@rollup/plugin-replace";import c from"@rollup/plugin-terser";import l from"dotenv";import{rollup as m}from"rollup";import d from"rollup-plugin-analyzer";import{externals as u}from"rollup-plugin-node-externals";import{string as f}from"rollup-plugin-string";import g from"rollup-plugin-ts";import b from"node:url";import*as h from"node:child_process";const v={command:"build [package]",describe:"Build a package",builder:{target:{description:"A target format: app or lib",type:"string",require:!0,alias:"t"},input:{description:'A file path of main source code. Default value is "src/index.ts" from package directory.',type:"string",alias:"i"},firebase:{description:"A file path of firebase.json.",type:"string"},"core-js":{description:"Whether or not core-js is employed.",type:"boolean",default:!1},minify:{description:"Whether or not minification is enabled.",type:"boolean",default:!0},sourcemap:{description:"Whether or not sourcemap is enabled.",type:"boolean",default:!0},external:{description:"Additional external dependencies.",type:"array"},verbose:{description:"Whether or not verbose mode is enabled.",type:"boolean",alias:"v"},env:{description:"Environment variables to be inlined.",type:"array",alias:"e"},dotenv:{description:".env files to be inlined.",type:"array"}},async handler(e){"app"!==e.target&&"lib"!==e.target&&(console.error('target option must be "app" or "lib"'),process.exit(1));let r=e.package?.toString()??".";r.endsWith("package.json")||(r=s.resolve(r,"package.json"));const l=await o.promises.readFile(r,"utf8"),h=JSON.parse(l);h&&h.main||(console.error('Please add "main" property in package.json.'),process.exit(1));const v=h.main,x=s.dirname(r),S=e.input||s.join(x,"src","index.ts");let w=s.join(x,v);e.coreJs&&(process.env.BUILD_TS_COREJS="1"),e.verbose&&(process.env.BUILD_TS_VERBOSE="1"),process.env.BUILD_TS_TARGET=e.target;const[O,k]=function(e){const r=e.name?.toString()||"",o=/@([^/]+)\/(.+)/.exec(r),[,s,i]=o||[];return[s,i]}(h),_=function(e,r,o){const l=[...e.external??[]].map((e=>e.toString()));r?.dependencies?.["@prisma/client"]&&l.push("prisma-client");const m=[".cjs",".mjs",".js",".jsx",".json",".cts",".mts",".ts",".tsx"],h=s.join(b.fileURLToPath(s.dirname(s.dirname(import.meta.url))),"babel.config.mjs"),v=[p({delimiters:["",""],preventAssignment:!0,values:y(e)}),t(),u({deps:!0,devDeps:!1,include:l,exclude:o&&new RegExp(`${o}\\/.+`)}),a({extensions:m}),n()];"app"===e.target?v.push(i({configFile:h,extensions:m,babelHelpers:"bundled",exclude:"node_modules/**"})):v.push(g({transpiler:"babel",babelConfig:h}));v.push(f({include:["**/*.csv","**/*.txt"]})),e.minify&&v.push(c());return v.push(d({summaryOnly:!0})),v}(e,h,O),N="app"===e.target&&e.firebase&&o.existsSync(e.firebase);N&&(w=await async function(e,r,i,n){const t=await o.promises.readFile(e,"utf8"),a=JSON.parse(t),p=s.resolve(s.dirname(e),a.functions.source);return r=s.join(p,s.basename(n)),await o.promises.rm(p,{recursive:!0,force:!0}),await o.promises.mkdir(p,{recursive:!0}),i.name+="-dist",i.main=s.relative(p,r),delete i.devDependencies,await o.promises.writeFile(s.join(p,"package.json"),JSON.stringify(i)),r}(e.firebase,w,h,v));const A=function(e,r,o,i){const n=[];if("app"===e.target)n.push({file:r,format:".mjs"===s.extname(r)?"module":"commonjs",sourcemap:e.sourcemap});else{const r=[[o.main,".mjs"===s.extname(o.main??"")?"module":"commonjs"],[o.module,"module"]];for(const[o,t]of r)o&&n.push({dir:j(s.dirname(o),i),format:t,preserveModules:!0,sourcemap:e.sourcemap})}return n}(e,w,h,k);let E;process.chdir(x);let J=!1;try{const[e]=await Promise.all([m({input:S,plugins:_}),!N&&o.promises.rm(s.dirname(w),{recursive:!0,force:!0})]);await Promise.all(A.map((r=>e.write(r)))),E=e}catch(e){J=!0,console.error("Filed to build due to:",e)}await(E?.close()),J&&process.exit(1)}};function y(e){const r={};for(const o of(e.env??[]).map((e=>e.toString())))void 0!==process.env[o]&&(r[`process.env.${o}`]=JSON.stringify(process.env[o]));for(const o of e.dotenv??[]){const e=l.config({path:o.toString()}).parsed||{};for(const[o,s]of Object.entries(e))void 0!==s&&(r[`process.env.${o}`]=JSON.stringify(s))}return r}function j(e,r){if(!r)return e;const o=e.indexOf(r);return o<0?e:e.slice(0,o)}const x={command:"run <file>",describe:"Run script",builder:{module:{description:"A module type: cjs or esm",type:"string",alias:"m"},watch:{description:"Whether watch mode is enabled or not",type:"boolean",alias:"w"}},async handler(e){const r=e.file?.toString()||"",i=await async function(e,r){if("cjs"===r||e.endsWith(".cts"))return"cjs";if("esm"===r||e.endsWith(".mts"))return"esm";let i=s.dirname(e);for(;;){const e=s.join(i,"package.json");if(o.existsSync(e)){try{const r=await o.promises.readFile(e,"utf8");if("module"===JSON.parse(r).type)return"esm"}catch{}break}const r=s.dirname(i);if(!r||r===i)break;i=r}return"cjs"}(r,e.module),n=["--no-warnings"];e.watch&&n.push("--watch"),"cjs"===i?n.push("--require","ts-node/register"):n.push("--loader","ts-node/esm"),n.push(r);const[,...t]=e._;h.spawnSync("node",[...n,...t.map((e=>e.toString()))],{shell:!0,stdio:"inherit",env:{...process.env,TS_NODE_TRANSPILE_ONLY:"1"}})}};await e(r(process.argv)).command(v).command(x).demandCommand().help().argv;
2
2
  //# sourceMappingURL=index.min.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "build-ts",
3
- "version": "3.1.2",
3
+ "version": "3.1.3",
4
4
  "repository": "github:WillBooster/build-ts",
5
5
  "license": "UNLICENSED",
6
6
  "author": "WillBooster Inc.",
@@ -23,6 +23,7 @@
23
23
  "postpack": "pinst --enable",
24
24
  "prettify": "prettier --cache --color --write \"**/{.*/,}*.{cjs,css,cts,htm,html,js,json,json5,jsx,md,mjs,mts,scss,ts,tsx,vue,yaml,yml}\" \"!**/test-fixtures/**\"",
25
25
  "start": "node --no-warnings --loader ts-node/esm src/index.ts",
26
+ "start-prod": "yarn build && yarn build-ts",
26
27
  "typecheck": "tsc --noEmit --Pretty"
27
28
  },
28
29
  "prettier": "@willbooster/prettier-config",