@wrdagency/react-islands 2.0.6 → 2.0.8

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.
package/bin/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import e,{readFileSync as n}from"fs";import t from"yocto-spinner";import r from"@rollup/plugin-commonjs";import o from"@rollup/plugin-node-resolve";import s from"@rollup/plugin-replace";import i from"@rollup/plugin-terser";import a from"@rollup/plugin-typescript";import c from"path";import{rollup as l}from"rollup";import{typescriptPaths as p}from"rollup-plugin-typescript-paths";import{exec as u}from"child_process";import{promisify as m}from"util";import d from"command-line-args";import f from"command-line-usage";function g(e,n){let t="";return t+=function(e){return`import * as ${y(e)} from "${e}";\n`}(e),t+=`${n} = ${y(e)};\n`,t}function y(e){return e.replace(/^@/,"").replace(/\//g,"_").replace(/[-_](.)/g,(e,n)=>n.toUpperCase()).replace(/^[a-z]/,e=>e.toUpperCase())}const h=e=>({name:e.name,input:e.input,output:e.output||"./dist/",minify:j(e.minify,!0),ssg:j(e.ssg,!0),jsx:e.jsx||"react-jsx",typescript:j(e.ssg,!1),common:v(e.common||["react","react-dom/client","@wrdagency/react-islands"])}),j=(e,n)=>!1!==e&&(!0===e||n),v=(e=[""])=>Array.isArray(e)?e.reduce((e,n)=>({...e,[n]:"Islands._Common."+y(n)}),{}):e,w=m(u),x=async e=>{try{const{stdout:n,stderr:t}=await w(e);return n&&console.log(n),t&&console.error(t),n}catch(e){throw console.error(e),e}};function b(n){const{deleteAfterRunning:t=!1}=n;return{name:"rollup-plugin-run-script-after-builder",writeBundle(n,r){const o=n.dir?n.dir:c.dirname(n.file||"");for(const[n,s]of Object.entries(r)){const r=c.resolve(o,n);if("chunk"!==s.type||!s.isEntry)return;if(!r&&!r.endsWith("js"))return;if(!e.existsSync(r))return;x(`node ${r}`).then(()=>{t&&e.unlinkSync(r)})}}}}function $(e){const{dependencies:n,namespace:t=""}=e,r="\0virtual-entry";return{name:"rollup-plugin-virtualize-dependency",resolveId:e=>"virtual-entry"===e?r:null,load(e){if(e!==r)return null;let o=function(e){return e.split(".").filter(Boolean).map((e,n,t)=>{const r="window."+t.slice(0,n+1).join(".");return`${r} = ${r} || {}`}).join(";\n")}(t)+";\n";for(const[e,t]of Object.entries(n))o+=g(e,t);return o}}}function O(e){const n=h(e),{name:t,input:c,output:l,minify:u,ssg:m,jsx:d,typescript:f,common:g}=n,y=[],j=e=>{const{active:n=!0,name:m=`Islands.${t}`,subName:g,format:y,globals:h={},prefix:j,suffix:v,plugins:w=[]}=e;return n?{input:c,external:Object.keys(h),jsx:d,output:{name:m,globals:h,format:y,entryFileNames:`[name]/${g}`,dir:l,banner:j&&(e=>j(e.name)),footer:v&&(e=>v(e.name))},plugins:[o({extensions:[".cjs",".mjs",".js",".json",".node",".jsx",".ts",".tsx"]}),r(),s({preventAssignment:!0,"process.env.NODE_ENV":JSON.stringify("production")}),u&&i(),f&&a({jsx:d}),f&&p(),...w]}:null};return y.push(j({active:!0,subName:"client.js",format:"iife",globals:g,suffix:e=>`\nwindow.Islands['${e}']?.render('${e}')`})),y.push(j({active:m,subName:"server.cjs",format:"cjs",suffix:()=>`var server = require('react-dom/server');\n\tvar fs = require('node:fs/promises');\n\tvar path = require('node:path');\nconst html = server.renderToString( module.exports.component( {} ) );\nconst file = path.resolve(__dirname, '${"ssg.html"}');\nfs.writeFile(file, html, { flag: "w+" });`,plugins:[b({deleteAfterRunning:!0})]})),y.filter(k)}function k(e){return null!==e}async function N(e,n){let t,r=!1;try{t=await l(e),await t.write(n)}catch(e){r=!0,console.error(e)}return t&&await t.close(),!r}!async function(e){const{command:n,help:t=!1,_unknown:r=[]}=d([{name:"command",type:String,defaultOption:!0},{name:"help",alias:"h",type:Boolean,description:"Display this usage guide."}],{stopAtFirstUnknown:!0});if(n&&n in e)return e[n].run([...r,t&&"--help"].filter(Boolean));if(t){const n=Object.keys(e).map(n=>({name:n,summary:e[n].description})),t=f([{header:"Synopsis",content:"npx react-islands <command> <options>"},{header:"Command List",content:n}]);console.log(t)}else console.error(`Command '${n}' not recognized by React Islands.`)}({build:new class{args;callback;description;constructor(e){let{args:n,callback:t,description:r}=e;n.push({name:"help",alias:"h",type:Boolean,description:"Display this usage guide."}),this.args=n,this.callback=t,this.description=r}run(e){const{help:n,...t}=d(this.args,{argv:e});if(!n)return this.callback(t);console.log(f([{header:"Options",optionList:this.args}]))}}({description:"Build and statically render the islands.",args:[{name:"config",type:String,alias:"c",description:"The config file to use.",defaultValue:"islands.config.json"}],callback:async e=>{const{config:a}=e,l=JSON.parse(n(a,"utf8")),{islands:p,...u}=l;if(!1!==u.common){const e=t({text:"Creating common dependencies file..."}).start(),n=function(e){const n=h(e),{output:t,minify:a,jsx:l,common:p}=n;return{input:"virtual-entry",jsx:l,output:{name:"Islands._Common",file:c.resolve(t,"common.js"),format:"iife"},plugins:[s({preventAssignment:!0,"process.env.NODE_ENV":JSON.stringify("production")}),$({dependencies:p,namespace:"Islands._Common"}),o(),r(),a&&i()]}}(u),{output:a,...l}=n;await N(l,a)?e.success("Succeeded: common dependencies file"):e.warning("Failed: common dependencies file")}for(const[e,n]of Object.entries(p)){const r=t({text:`Creating island ${e}...`}).start(),o=O({input:n,name:e,...u});let s=!1;for(const e of o){const{output:n,...t}=e;await N(t,n)||(s=!0)}o.map(async e=>{}),s?r.warning(`Failed island: ${e}`):r.success(`Succeeded island: ${e}`)}}})});
2
+ import e,{readFileSync as n}from"fs";import t from"yocto-spinner";import r from"@rollup/plugin-commonjs";import o from"@rollup/plugin-node-resolve";import s from"@rollup/plugin-replace";import i from"@rollup/plugin-terser";import a from"@rollup/plugin-typescript";import c from"path";import{rollup as l}from"rollup";import{typescriptPaths as u}from"rollup-plugin-typescript-paths";import{exec as p}from"child_process";import{promisify as m}from"util";import d from"command-line-args";import f from"command-line-usage";function g(e,n){let t="";return t+=function(e){return`import * as ${y(e)} from "${e}";\n`}(e),t+=`${n} = ${y(e)};\n`,t}function y(e){return e.replace(/^@/,"").replace(/\//g,"_").replace(/[-_](.)/g,(e,n)=>n.toUpperCase()).replace(/^[a-z]/,e=>e.toUpperCase())}const h=e=>({name:e.name,input:e.input,output:e.output||"./dist/",minify:j(e.minify,!0),ssg:j(e.ssg,!0),jsx:e.jsx||"react-jsx",typescript:j(e.ssg,!1),common:v(e.common||["react","react-dom/client","@wrdagency/react-islands"])}),j=(e,n)=>!1!==e&&(!0===e||n),v=(e=[""])=>Array.isArray(e)?e.reduce((e,n)=>({...e,[n]:"Islands._Common."+y(n)}),{}):e,w=m(p),x=async e=>{try{const{stdout:n,stderr:t}=await w(e);return n&&console.log(n),t&&console.error(t),n}catch(e){throw console.error(e),e}};function b(n){const{deleteAfterRunning:t=!1}=n;return{name:"rollup-plugin-run-script-after-builder",writeBundle(n,r){const o=n.dir?n.dir:c.dirname(n.file||"");for(const[n,s]of Object.entries(r)){const r=c.resolve(o,n);if("chunk"!==s.type||!s.isEntry)return;if(!r&&!r.endsWith("js"))return;if(!e.existsSync(r))return;x(`node ${r}`).then(()=>{t&&e.unlinkSync(r)})}}}}function $(e){const{dependencies:n,namespace:t=""}=e,r="\0virtual-entry";return{name:"rollup-plugin-virtualize-dependency",resolveId:e=>"virtual-entry"===e?r:null,load(e){if(e!==r)return null;let o=function(e){return e.split(".").filter(Boolean).map((e,n,t)=>{const r="window."+t.slice(0,n+1).join(".");return`${r} = ${r} || {}`}).join(";\n")}(t)+";\n";for(const[e,t]of Object.entries(n))o+=g(e,t);return o}}}function O(e){const n=h(e),{name:t,input:c,output:l,minify:p,ssg:m,jsx:d,typescript:f,common:g}=n,y=[],j=e=>{const{active:n=!0,name:m=`Islands.${t}`,subName:g,format:y,globals:h={},prefix:j,suffix:v,plugins:w=[]}=e;return n?{input:c,external:Object.keys(h),jsx:d,output:{name:m,globals:h,format:y,entryFileNames:`[name]/${g}`,dir:l,banner:j&&(e=>j(e.name)),footer:v&&(e=>v(e.name))},plugins:[o({extensions:[".cjs",".mjs",".js",".json",".node",".jsx",".ts",".tsx"]}),r(),s({preventAssignment:!0,"process.env.NODE_ENV":JSON.stringify("production")}),p&&i(),f&&a({outDir:l,declaration:!1,jsx:d}),f&&u(),...w]}:null};return y.push(j({active:!0,subName:"client.js",format:"iife",globals:g,suffix:e=>`\nwindow.Islands['${e}']?.render('${e}')`})),y.push(j({active:m,subName:"server.cjs",format:"cjs",suffix:()=>`var server = require('react-dom/server');\n\tvar fs = require('node:fs/promises');\n\tvar path = require('node:path');\nconst html = server.renderToString( module.exports.component( {} ) );\nconst file = path.resolve(__dirname, '${"ssg.html"}');\nfs.writeFile(file, html, { flag: "w+" });`,plugins:[b({deleteAfterRunning:!0})]})),y.filter(k)}function k(e){return null!==e}async function N(e,n){let t,r=!1;try{t=await l(e),await t.write(n)}catch(e){r=!0,console.error(e)}return t&&await t.close(),!r}!async function(e){const{command:n,help:t=!1,_unknown:r=[]}=d([{name:"command",type:String,defaultOption:!0},{name:"help",alias:"h",type:Boolean,description:"Display this usage guide."}],{stopAtFirstUnknown:!0});if(n&&n in e)return e[n].run([...r,t&&"--help"].filter(Boolean));if(t){const n=Object.keys(e).map(n=>({name:n,summary:e[n].description})),t=f([{header:"Synopsis",content:"npx react-islands <command> <options>"},{header:"Command List",content:n}]);console.log(t)}else console.error(`Command '${n}' not recognized by React Islands.`)}({build:new class{args;callback;description;constructor(e){let{args:n,callback:t,description:r}=e;n.push({name:"help",alias:"h",type:Boolean,description:"Display this usage guide."}),this.args=n,this.callback=t,this.description=r}run(e){const{help:n,...t}=d(this.args,{argv:e});if(!n)return this.callback(t);console.log(f([{header:"Options",optionList:this.args}]))}}({description:"Build and statically render the islands.",args:[{name:"config",type:String,alias:"c",description:"The config file to use.",defaultValue:"islands.config.json"}],callback:async e=>{const{config:a}=e,l=JSON.parse(n(a,"utf8")),{islands:u,...p}=l;if(!1!==p.common){const e=t({text:"Creating common dependencies file..."}).start(),n=function(e){const n=h(e),{output:t,minify:a,jsx:l,common:u}=n;return{input:"virtual-entry",jsx:l,output:{name:"Islands._Common",file:c.resolve(t,"common.js"),format:"iife"},plugins:[s({preventAssignment:!0,"process.env.NODE_ENV":JSON.stringify("production")}),$({dependencies:u,namespace:"Islands._Common"}),o(),r(),a&&i()]}}(p),{output:a,...l}=n;await N(l,a)?e.success("Succeeded: common dependencies file"):e.warning("Failed: common dependencies file")}for(const[e,n]of Object.entries(u)){const r=t({text:`Creating island ${e}...`}).start(),o=O({input:n,name:e,...p});let s=!1;for(const e of o){const{output:n,...t}=e;await N(t,n)||(s=!0)}o.map(async e=>{}),s?r.warning(`Failed island: ${e}`):r.success(`Succeeded island: ${e}`)}}})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@wrdagency/react-islands",
4
- "version": "2.0.6",
4
+ "version": "2.0.8",
5
5
  "description": "",
6
6
  "main": "./dist/index.js",
7
7
  "files": [
@@ -85,6 +85,8 @@ export function createRollupConfigs(options: BuildOptions): RollupOptions[] {
85
85
  minify && terserPlugin(),
86
86
  typescript &&
87
87
  typescriptPlugin({
88
+ outDir: output,
89
+ declaration: false,
88
90
  jsx,
89
91
  }),
90
92
  typescript && typescriptPathsPlugin(),