@wrdagency/react-islands 2.1.1 → 2.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.
package/bin/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import e from"@rollup/plugin-commonjs";import n from"@rollup/plugin-node-resolve";import t from"@rollup/plugin-replace";import o from"@rollup/plugin-terser";import r from"path";import{rollup as s,watch as i}from"rollup";import a from"@rollup/plugin-typescript";import{typescriptPaths as c}from"rollup-plugin-typescript-paths";import l,{readFileSync as u}from"fs";import{exec as p}from"child_process";import{promisify as m}from"util";import d from"yocto-spinner";import f from"command-line-args";import g from"command-line-usage";class h{lines=[];import(e,n){return n||(n=h.packageNameToProperty(e)),this.add(`import * as ${n} from "${e}"`)}createGlobalObject(e){return this.add(e.split(".").map(e=>e.trim()).filter(Boolean).map((e,n,t)=>{const o="window."+t.slice(0,n+1).join(".");return`${o} = ${o} || {}`}))}setGlobalObjectProperty(e,n,t){return this.add(`window.${e}['${n}'] = ${t}`)}static packageNameToProperty(e){return e.replace(/^@/,"").replace(/\//g,"_").replace(/[-_](.)/g,(e,n)=>n.toUpperCase()).replace(/^[a-z]/,e=>e.toUpperCase())}static renderReactComponentToFile(e,n){return`var server = require('react-dom/server');\nvar fs = require('node:fs/promises');\nvar path = require('node:path');\nconst html = server.renderToString( ${n}( {} ) );\nconst file = path.resolve(__dirname, '${e}');\nfs.writeFile(file, html, { flag: "w+" });`}add(e){return Array.isArray(e)?this.lines.push(...e):this.lines.push(e),this}out(){return this.lines.join(";\n")}}function y(e){const{dependencies:n,namespace:t=""}=e,o="\0virtual-entry";return{name:"rollup-plugin-virtualize-dependency",resolveId:e=>"virtual-entry"===e?o:null,load(e){if(e!==o)return null;const r=new h;r.createGlobalObject(t);for(const e of n){const n=h.packageNameToProperty(e);r.import(e,n),r.setGlobalObjectProperty(t,n,n)}return r.out()}}}async function w(e){const{output:n,...t}=e;let o,r=!1;try{o=await s(t),await o.write(n)}catch(e){r=!0,console.error(e)}return o&&await o.close(),!r}function j(e){const{output:n,...t}=e,o=i({...t,output:n,watch:{clearScreen:!1}});return o.on("event",e=>{"BUNDLE_END"===e.code&&e.result&&e.result.close()}),o}function b(s){const{output:i,minify:a,jsx:c,common:l}=s;return{input:"virtual-entry",jsx:c,output:{name:"Islands._Common",file:r.resolve(i,"common.js"),format:"iife"},plugins:[t({preventAssignment:!0,"process.env.NODE_ENV":JSON.stringify("production")}),y({dependencies:l,namespace:"Islands._Common"}),n(),e(),a&&o()]}}const v=m(p);class ${line(e){console.log(e)}async spinner(e,n){const t=d({text:`${e}...`}).start();await n()?t.success(`Succeeded: ${e}`):t.warning(`Failed: ${e}`)}watcher(e,n){const t=d({text:`Rebuilding ${e}...`});let o=0;n.on("event",n=>{if("START"===n.code)t.clear(),t.start(),o=Date.now();else if("END"===n.code){const n=Date.now()-o;t.success(`Rebuilt: ${e} in ${n}ms.`)}else"ERROR"===n.code&&(t.warning(`Failed: ${e}`),console.error(n.error))})}async command(e){try{const{stdout:n,stderr:t}=await v(e);return n&&console.log(n),t&&console.error(t),n}catch(e){throw console.error(e),e}}}function x(e){const{deleteAfterRunning:n=!1}=e;return{name:"rollup-plugin-run-script-after-builder",writeBundle(e,t){const o=e.dir?e.dir:r.dirname(e.file||"");for(const[e,s]of Object.entries(t)){const t=r.resolve(o,e);if("chunk"!==s.type||!s.isEntry)return;if(!t&&!t.endsWith("js"))return;if(!l.existsSync(t))return;(new $).command(`node ${t}`).then(()=>{n&&l.unlinkSync(t)})}}}}function N(r,s){const{name:i,input:l,output:u,minify:p,ssg:m,jsx:d,typescript:f,common:g,define:h}=r,{name:y=`Islands.${i}`,subName:w,format:j,globals:b={},prefix:v,suffix:$,plugins:x=[]}=s;return{input:l,external:Object.keys(b),jsx:d,output:{name:y,globals:b,format:j,entryFileNames:`[name]/${w}`,dir:u,banner:v&&(e=>v(e.name)),footer:$&&(e=>$(e.name))},plugins:[n({extensions:[".cjs",".mjs",".js",".json",".node",".jsx",".ts",".tsx"]}),e(),t({preventAssignment:!0,values:{...h,"process.env.NODE_ENV":JSON.stringify("production")}}),p&&o(),f&&a({outputToFilesystem:!0,noForceEmit:!0,compilerOptions:{outDir:u,jsx:d}}),f&&c(),...x]}}function O(e){return N(e,{subName:"client.js",format:"iife",globals:e.common.reduce((e,n)=>({...e,[n]:`Islands._Common["${h.packageNameToProperty(n)}"]`}),{}),suffix:e=>`\nwindow.Islands['${e}']?.render('${e}')`})}function k(e){const n=[O(e)];return e.ssg&&n.push(function(e){return N(e,{subName:"server.cjs",format:"cjs",suffix:()=>h.renderReactComponentToFile("ssg.html","module.exports.component"),plugins:[x({deleteAfterRunning:!0})]})}(e)),n}function S(e){return async function(e){let n=!0;for(const t of e)await w(t)||(n=!1);return n}(k(e))}function C(e){return j(O(e))}class T{args;callback;description;constructor(e){let{args:n,callback:t,description:o}=e;n.push({name:"help",alias:"h",type:Boolean,description:"Display this usage guide."}),this.args=n,this.callback=t,this.description=o}run(e){const{help:n,...t}=f(this.args,{argv:e});if(!n)return this.callback(t);console.log(g([{header:"Options",optionList:this.args}]))}}function _(e){const n=u(e,"utf8");return function(e){const n=(e,n)=>!1!==e&&(!0===e||n);return{islands:e.islands,output:e.output||"./dist/",minify:n(e.minify,!0),ssg:n(e.ssg,!0),jsx:e.jsx||"react-jsx",typescript:n(e.ssg,!1),common:e.common||["react","react/jsx-runtime","react-dom/client","@wrdagency/react-islands"],define:e.define||{}}}(JSON.parse(n))}!async function(e){const{command:n,help:t=!1,_unknown:o=[]}=f([{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([...o,t&&"--help"].filter(Boolean));if(t){const n=Object.keys(e).map(n=>({name:n,summary:e[n].description})),t=g([{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 T({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:n}=e,t=new $,o=_(n);o.common&&await t.spinner("Creating common dependencies file",async()=>w(b(o)));for(const[e,n]of Object.entries(o.islands))await t.spinner(`Creating island ${e}`,()=>S({name:e,input:n,...o}))}}),watch:new T({description:"Watch & build the islands for development",args:[{name:"config",type:String,alias:"c",description:"The config file to use.",defaultValue:"islands.config.json"}],callback:async e=>{const{config:n}=e,t=new $,o=_(n);if(o.common){const e=j(b(o));t.watcher("Common Dependencies",e)}for(const[e,n]of Object.entries(o.islands)){const r=C({name:e,input:n,...o});t.watcher(e,r)}}})});
2
+ import e from"@rollup/plugin-commonjs";import n from"@rollup/plugin-node-resolve";import t from"@rollup/plugin-replace";import o from"@rollup/plugin-terser";import r from"path";import{rollup as s,watch as i}from"rollup";import a from"@rollup/plugin-typescript";import{typescriptPaths as c}from"rollup-plugin-typescript-paths";import l,{readFileSync as u}from"fs";import{exec as p}from"child_process";import{promisify as m}from"util";import d from"yocto-spinner";import f from"command-line-args";import g from"command-line-usage";class h{lines=[];import(e,n){return n||(n=h.packageNameToProperty(e)),this.add(`import * as ${n} from "${e}"`)}createGlobalObject(e){return this.add(e.split(".").map(e=>e.trim()).filter(Boolean).map((e,n,t)=>{const o="window."+t.slice(0,n+1).join(".");return`${o} = ${o} || {}`}))}setGlobalObjectProperty(e,n,t){return this.add(`window.${e}['${n}'] = ${t}`)}static packageNameToProperty(e){return e.replace(/^@/,"").replace(/\//g,"_").replace(/[-_](.)/g,(e,n)=>n.toUpperCase()).replace(/^[a-z]/,e=>e.toUpperCase())}static renderReactComponentToFile(e,n){return`var server = require('react-dom/server');\nvar fs = require('node:fs/promises');\nvar path = require('node:path');\nconst html = server.renderToString( ${n}( {} ) );\nconst file = path.resolve(__dirname, '${e}');\nfs.writeFile(file, html, { flag: "w+" });`}add(e){return Array.isArray(e)?this.lines.push(...e):this.lines.push(e),this}out(){return this.lines.join(";\n")}}function y(e){const{dependencies:n,namespace:t=""}=e,o="\0virtual-entry";return{name:"rollup-plugin-virtualize-dependency",resolveId:e=>"virtual-entry"===e?o:null,load(e){if(e!==o)return null;const r=new h;r.createGlobalObject(t);for(const e of n){const n=h.packageNameToProperty(e);r.import(e,n),r.setGlobalObjectProperty(t,n,n)}return r.out()}}}async function w(e){const{output:n,...t}=e;let o,r=!1;try{o=await s(t),await o.write(n)}catch(e){r=!0,console.error(e)}return o&&await o.close(),!r}function b(e){const{output:n,...t}=e,o=i({...t,output:n,watch:{clearScreen:!1}});return o.on("event",e=>{"BUNDLE_END"===e.code&&e.result&&e.result.close()}),o}function j(s){const{output:i,minify:a,jsx:c,common:l}=s;return{input:"virtual-entry",jsx:c,output:{name:"Islands._Common",file:r.resolve(i,"common.js"),format:"iife"},plugins:[t({preventAssignment:!0,"process.env.NODE_ENV":JSON.stringify("production")}),y({dependencies:l,namespace:"Islands._Common"}),n(),e(),a&&o()]}}const v=m(p);class ${line(e){console.log(e)}async spinner(e,n){const t=d({text:`${e}...`}).start();await n()?t.success(`Succeeded: ${e}`):t.warning(`Failed: ${e}`)}watcher(e,n){const t=d({text:`Rebuilding ${e}...`});let o=0;n.on("event",n=>{if("START"===n.code)t.clear(),t.start(),o=Date.now();else if("END"===n.code){const n=Date.now()-o;t.success(`Rebuilt: ${e} in ${n}ms.`)}else"ERROR"===n.code&&(t.warning(`Failed: ${e}`),console.error(n.error))})}async command(e){try{const{stdout:n,stderr:t}=await v(e);return n&&console.log(n),t&&console.error(t),n}catch(e){throw console.error(e),e}}}function x(e){const{deleteAfterRunning:n=!1}=e;return{name:"rollup-plugin-run-script-after-builder",writeBundle(e,t){const o=e.dir?e.dir:r.dirname(e.file||"");for(const[e,s]of Object.entries(t)){const t=r.resolve(o,e);if("chunk"!==s.type||!s.isEntry)return;if(!t&&!t.endsWith("js"))return;if(!l.existsSync(t))return;(new $).command(`node ${t}`).then(()=>{n&&l.unlinkSync(t)})}}}}function N(r,s){const{name:i,input:l,output:u,minify:p,ssg:m,jsx:d,typescript:f,common:g,define:h}=r,{subName:y,format:w,globals:b={},prefix:j,suffix:v,plugins:$=[]}=s;return{input:l,external:Object.keys(b),jsx:d,output:{name:`Islands.${i}`,globals:b,format:w,entryFileNames:`[name]/${y}`,dir:u,banner:j&&(e=>j(e.name)),footer:v&&(e=>v(e.name))},plugins:[n({extensions:[".cjs",".mjs",".js",".json",".node",".jsx",".ts",".tsx"]}),e(),f&&a({outputToFilesystem:!1,noForceEmit:!0,compilerOptions:{outDir:u,jsx:d}}),f&&c(),t({preventAssignment:!0,values:{...h,"process.env.NODE_ENV":JSON.stringify("production")}}),p&&o(),...$]}}function O(e){return N(e,{subName:"client.js",format:"iife",globals:e.common.reduce((e,n)=>({...e,[n]:`Islands._Common["${h.packageNameToProperty(n)}"]`}),{}),suffix:()=>`\nwindow.Islands['${e.name}']?.render('${e.name}')`})}function k(e){const n=[O(e)];return e.ssg&&n.push(function(e){return N(e,{subName:"server.cjs",format:"cjs",suffix:()=>h.renderReactComponentToFile("ssg.html","module.exports.component"),plugins:[x({deleteAfterRunning:!0})]})}(e)),n}function S(e){return async function(e){let n=!0;for(const t of e)await w(t)||(n=!1);return n}(k(e))}function C(e){return b(O(e))}class T{args;callback;description;constructor(e){let{args:n,callback:t,description:o}=e;n.push({name:"help",alias:"h",type:Boolean,description:"Display this usage guide."}),this.args=n,this.callback=t,this.description=o}run(e){const{help:n,...t}=f(this.args,{argv:e});if(!n)return this.callback(t);console.log(g([{header:"Options",optionList:this.args}]))}}function _(e){const n=u(e,"utf8");return function(e){const n=(e,n)=>"boolean"==typeof e?e:n;return{islands:e.islands,output:e.output||"./dist/",minify:n(e.minify,!0),ssg:n(e.ssg,!0),jsx:e.jsx||"react-jsx",typescript:n(e.typescript,!0),common:e.common||["react","react/jsx-runtime","react-dom/client","@wrdagency/react-islands"],define:e.define||{}}}(JSON.parse(n))}!async function(e){const{command:n,help:t=!1,_unknown:o=[]}=f([{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([...o,t&&"--help"].filter(Boolean));if(t){const n=Object.keys(e).map(n=>({name:n,summary:e[n].description})),t=g([{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 T({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:n}=e,t=new $,o=_(n);o.common&&await t.spinner("Creating common dependencies file",async()=>w(j(o)));for(const[e,n]of Object.entries(o.islands))await t.spinner(`Creating island ${e}`,()=>S({name:e,input:n,...o}))}}),watch:new T({description:"Watch & build the islands for development",args:[{name:"config",type:String,alias:"c",description:"The config file to use.",defaultValue:"islands.config.json"}],callback:async e=>{const{config:n}=e,t=new $,o=_(n);if(o.common){const e=b(j(o));t.watcher("Common Dependencies",e)}for(const[e,n]of Object.entries(o.islands)){const r=C({name:e,input:n,...o});t.watcher(e,r)}}})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@wrdagency/react-islands",
4
- "version": "2.1.1",
4
+ "version": "2.1.3",
5
5
  "description": "",
6
6
  "main": "./dist/index.js",
7
7
  "files": [
@@ -42,6 +42,7 @@
42
42
  "react-dom": "^19.1.0"
43
43
  },
44
44
  "dependencies": {
45
+ "@rollup/plugin-alias": "^5.1.1",
45
46
  "@rollup/plugin-commonjs": "^28.0.6",
46
47
  "@rollup/plugin-json": "^6.1.0",
47
48
  "@rollup/plugin-node-resolve": "^16.0.1",
@@ -28,7 +28,7 @@ export default new Command({
28
28
  });
29
29
  }
30
30
 
31
- // 2. Setup watcher for each island.
31
+ // 2. Build each island.
32
32
  for (const [name, input] of Object.entries(config.islands)) {
33
33
  await output.spinner(`Creating island ${name}`, () => {
34
34
  return buildIsland({
@@ -21,7 +21,7 @@ export default new Command({
21
21
  const output = new Output();
22
22
  const config = readConfig(configPath);
23
23
 
24
- // 1. Build common dependencies.
24
+ // 1. Watch common dependencies.
25
25
  if (config.common) {
26
26
  const watcher = watchCommon(config);
27
27
  output.watcher("Common Dependencies", watcher);
@@ -1,146 +1,137 @@
1
- import commonjsPlugin from "@rollup/plugin-commonjs";
2
- import resolvePlugin from "@rollup/plugin-node-resolve";
3
- import replacePlugin from "@rollup/plugin-replace";
4
- import terserPlugin from "@rollup/plugin-terser";
5
- import typescriptPlugin from "@rollup/plugin-typescript";
6
- import { ModuleFormat, Plugin, RollupOptions } from "rollup";
7
- import { typescriptPaths as typescriptPathsPlugin } from "rollup-plugin-typescript-paths";
8
- import { CodeGen } from "../util/code-gen";
9
- import { IndividualIslandConfigOptions } from "../util/config";
10
- import { runScriptAfterBuildPlugin } from "./plugins/runScriptAfterBuildPlugin";
11
- import { runRollups, watchRollup } from "./run";
12
-
13
- function createIslandRollupConfig(
14
- config: IndividualIslandConfigOptions,
15
- opts: {
16
- name?: string;
17
- subName: string;
18
- format: ModuleFormat;
19
- globals?: Record<string, string>;
20
- prefix?: (name: string) => string;
21
- suffix?: (name: string) => string;
22
- plugins?: Plugin[];
23
- }
24
- ): RollupOptions {
25
- const { name, input, output, minify, ssg, jsx, typescript, common, define } =
26
- config;
27
-
28
- const {
29
- name: mainName = `Islands.${name}`,
30
- subName,
31
- format,
32
- globals = {},
33
- prefix,
34
- suffix,
35
- plugins = [],
36
- } = opts;
37
-
38
- return {
39
- input,
40
- external: Object.keys(globals),
41
- jsx,
42
- output: {
43
- name: mainName,
44
- globals,
45
- format,
46
- entryFileNames: `[name]/${subName}`,
47
- dir: output,
48
- banner: prefix && ((chunk) => prefix(chunk.name)),
49
- footer: suffix && ((chunk) => suffix(chunk.name)),
50
- },
51
- plugins: [
52
- resolvePlugin({
53
- extensions: [
54
- ".cjs",
55
- ".mjs",
56
- ".js",
57
- ".json",
58
- ".node",
59
- ".jsx",
60
- ".ts",
61
- ".tsx",
62
- ],
63
- }),
64
- commonjsPlugin(),
65
- replacePlugin({
66
- preventAssignment: true,
67
- values: {
68
- ...define,
69
- "process.env.NODE_ENV": JSON.stringify("production"),
70
- },
71
- }),
72
- minify && terserPlugin(),
73
- typescript &&
74
- typescriptPlugin({
75
- outputToFilesystem: true,
76
- noForceEmit: true,
77
- compilerOptions: {
78
- outDir: output,
79
- jsx,
80
- },
81
- }),
82
- typescript && typescriptPathsPlugin(),
83
- ...plugins,
84
- ],
85
- };
86
- }
87
-
88
- export function createIslandRollupConfigClient(
89
- config: IndividualIslandConfigOptions
90
- ): RollupOptions {
91
- return createIslandRollupConfig(config, {
92
- subName: "client.js",
93
- format: "iife",
94
- globals: config.common.reduce((globals, packageName) => {
95
- return {
96
- ...globals,
97
- [packageName]: `Islands._Common["${CodeGen.packageNameToProperty(
98
- packageName
99
- )}"]`,
100
- };
101
- }, {}),
102
- suffix: () =>
103
- `\nwindow.Islands['${config.name}']?.render('${config.name}')`,
104
- });
105
- }
106
-
107
- export function createIslandRollupConfigServer(
108
- config: IndividualIslandConfigOptions
109
- ): RollupOptions {
110
- return createIslandRollupConfig(config, {
111
- subName: "server.cjs",
112
- format: "cjs",
113
- suffix: () =>
114
- CodeGen.renderReactComponentToFile(
115
- "ssg.html",
116
- "module.exports.component"
117
- ),
118
- plugins: [
119
- runScriptAfterBuildPlugin({
120
- deleteAfterRunning: true,
121
- }),
122
- ],
123
- });
124
- }
125
-
126
- export function createIslandRollupConfigs(
127
- config: IndividualIslandConfigOptions
128
- ): RollupOptions[] {
129
- const configs: RollupOptions[] = [createIslandRollupConfigClient(config)];
130
-
131
- if (config.ssg) {
132
- configs.push(createIslandRollupConfigServer(config));
133
- }
134
-
135
- return configs;
136
- }
137
-
138
- export function buildIsland(
139
- options: IndividualIslandConfigOptions
140
- ): Promise<boolean> {
141
- return runRollups(createIslandRollupConfigs(options));
142
- }
143
-
144
- export function watchIsland(options: IndividualIslandConfigOptions) {
145
- return watchRollup(createIslandRollupConfigClient(options));
146
- }
1
+ import commonjsPlugin from "@rollup/plugin-commonjs";
2
+ import resolvePlugin from "@rollup/plugin-node-resolve";
3
+ import replacePlugin from "@rollup/plugin-replace";
4
+ import terserPlugin from "@rollup/plugin-terser";
5
+ import typescriptPlugin from "@rollup/plugin-typescript";
6
+ import { ModuleFormat, Plugin, RollupOptions } from "rollup";
7
+ import { typescriptPaths as typescriptPathsPlugin } from "rollup-plugin-typescript-paths";
8
+ import { CodeGen } from "../util/code-gen";
9
+ import { IndividualIslandConfigOptions } from "../util/config";
10
+ import { runScriptAfterBuildPlugin } from "./plugins/runScriptAfterBuildPlugin";
11
+ import { runRollups, watchRollup } from "./run";
12
+
13
+ function createIslandRollupConfig(
14
+ config: IndividualIslandConfigOptions,
15
+ opts: {
16
+ subName: string;
17
+ format: ModuleFormat;
18
+ globals?: Record<string, string>;
19
+ prefix?: (name: string) => string;
20
+ suffix?: (name: string) => string;
21
+ plugins?: Plugin[];
22
+ }
23
+ ): RollupOptions {
24
+ const { name, input, output, minify, ssg, jsx, typescript, common, define } =
25
+ config;
26
+
27
+ const { subName, format, globals = {}, prefix, suffix, plugins = [] } = opts;
28
+
29
+ return {
30
+ input,
31
+ external: Object.keys(globals),
32
+ jsx,
33
+ output: {
34
+ name: `Islands.${name}`,
35
+ globals,
36
+ format,
37
+ entryFileNames: `[name]/${subName}`,
38
+ dir: output,
39
+ banner: prefix && ((chunk) => prefix(chunk.name)),
40
+ footer: suffix && ((chunk) => suffix(chunk.name)),
41
+ },
42
+ plugins: [
43
+ resolvePlugin({
44
+ extensions: [
45
+ ".cjs",
46
+ ".mjs",
47
+ ".js",
48
+ ".json",
49
+ ".node",
50
+ ".jsx",
51
+ ".ts",
52
+ ".tsx",
53
+ ],
54
+ }),
55
+ commonjsPlugin(),
56
+ typescript &&
57
+ typescriptPlugin({
58
+ outputToFilesystem: false,
59
+ noForceEmit: true,
60
+ compilerOptions: {
61
+ outDir: output,
62
+ jsx,
63
+ },
64
+ }),
65
+ typescript && typescriptPathsPlugin(),
66
+ replacePlugin({
67
+ preventAssignment: true,
68
+ values: {
69
+ ...define,
70
+ "process.env.NODE_ENV": JSON.stringify("production"),
71
+ },
72
+ }),
73
+ minify && terserPlugin(),
74
+ ...plugins,
75
+ ],
76
+ };
77
+ }
78
+
79
+ export function createIslandRollupConfigClient(
80
+ config: IndividualIslandConfigOptions
81
+ ): RollupOptions {
82
+ return createIslandRollupConfig(config, {
83
+ subName: "client.js",
84
+ format: "iife",
85
+ globals: config.common.reduce((globals, packageName) => {
86
+ return {
87
+ ...globals,
88
+ [packageName]: `Islands._Common["${CodeGen.packageNameToProperty(
89
+ packageName
90
+ )}"]`,
91
+ };
92
+ }, {}),
93
+ suffix: () =>
94
+ `\nwindow.Islands['${config.name}']?.render('${config.name}')`,
95
+ });
96
+ }
97
+
98
+ export function createIslandRollupConfigServer(
99
+ config: IndividualIslandConfigOptions
100
+ ): RollupOptions {
101
+ return createIslandRollupConfig(config, {
102
+ subName: "server.cjs",
103
+ format: "cjs",
104
+ suffix: () =>
105
+ CodeGen.renderReactComponentToFile(
106
+ "ssg.html",
107
+ "module.exports.component"
108
+ ),
109
+ plugins: [
110
+ runScriptAfterBuildPlugin({
111
+ deleteAfterRunning: true,
112
+ }),
113
+ ],
114
+ });
115
+ }
116
+
117
+ export function createIslandRollupConfigs(
118
+ config: IndividualIslandConfigOptions
119
+ ): RollupOptions[] {
120
+ const configs: RollupOptions[] = [createIslandRollupConfigClient(config)];
121
+
122
+ if (config.ssg) {
123
+ configs.push(createIslandRollupConfigServer(config));
124
+ }
125
+
126
+ return configs;
127
+ }
128
+
129
+ export function buildIsland(
130
+ options: IndividualIslandConfigOptions
131
+ ): Promise<boolean> {
132
+ return runRollups(createIslandRollupConfigs(options));
133
+ }
134
+
135
+ export function watchIsland(options: IndividualIslandConfigOptions) {
136
+ return watchRollup(createIslandRollupConfigClient(options));
137
+ }
@@ -44,13 +44,7 @@ export function normalizeBuildOptions(
44
44
  value: boolean | undefined | null | void,
45
45
  fallback: boolean
46
46
  ): boolean => {
47
- if (value === false) {
48
- return false;
49
- } else if (value === true) {
50
- return true;
51
- } else {
52
- return fallback;
53
- }
47
+ return typeof value === "boolean" ? value : fallback;
54
48
  };
55
49
 
56
50
  return {
@@ -59,7 +53,7 @@ export function normalizeBuildOptions(
59
53
  minify: normalizeBoolean(options.minify, true),
60
54
  ssg: normalizeBoolean(options.ssg, true),
61
55
  jsx: options.jsx || "react-jsx",
62
- typescript: normalizeBoolean(options.ssg, false),
56
+ typescript: normalizeBoolean(options.typescript, true),
63
57
  common: options.common || [
64
58
  "react",
65
59
  "react/jsx-runtime",