@jahia/vite-plugin 0.5.3 → 0.5.5

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/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import multiEntry from '@rollup/plugin-multi-entry';
2
- import { createFilter, addExtension } from '@rollup/pluginutils';
3
- import { extname } from 'node:path';
2
+ import path$1 from 'node:path';
4
3
  import { styleText } from 'node:util';
5
4
  import { globSync } from 'tinyglobby';
6
5
  import { print } from 'esrap';
7
6
  import { walk } from 'zimmerframe';
7
+ import { createFilter } from '@rollup/pluginutils';
8
8
  import path from 'path';
9
9
 
10
10
  var sharedLibs = {
@@ -103,10 +103,8 @@ function buildSuccessPlugin(callback) {
103
103
  };
104
104
  }
105
105
  function jahia(options = {}) {
106
- const clientEntries = globSync(options.client?.input?.glob ?? "**/*.jsx", {
107
- cwd: options.client?.input?.dir ?? "./src/client/",
108
- absolute: true
109
- });
106
+ const clientBaseDir = options.client?.input?.dir ?? "./src/client/";
107
+ const clientEntries = globSync(options.client?.input?.glob ?? "**/*.jsx", { cwd: clientBaseDir });
110
108
  if (clientEntries.length === 0) {
111
109
  console.warn(
112
110
  `${styleText("yellowBright", "[@jahia/vite-plugin] Skipping client build because there are no entry files...")}
@@ -127,26 +125,25 @@ function jahia(options = {}) {
127
125
  * @see https://vite.dev/guide/api-plugin.html#config
128
126
  */
129
127
  config(config) {
130
- config.builder ??= { sharedConfigBuild: true };
131
128
  config.esbuild ??= { jsx: "automatic" };
132
129
  return {
130
+ // Build all environments https://vite.dev/guide/api-environment-frameworks.html#environments-during-build
131
+ builder: { sharedConfigBuild: true },
132
+ // Enforce bundling of all dependencies
133
+ ssr: { noExternal: true },
134
+ // Define the environments (client and ssr)
133
135
  environments: {
134
136
  client: {
135
137
  build: {
136
138
  lib: {
137
- // Single entry point for the client, all other files must be imported in this one
138
- entry: clientEntries,
139
+ entry: Object.fromEntries(
140
+ clientEntries.map((file) => [file, path$1.join(clientBaseDir, file)])
141
+ ),
139
142
  formats: ["es"]
140
143
  },
141
144
  rollupOptions: {
142
145
  output: {
143
- dir: options.client?.output ?? "./javascript/client/",
144
- entryFileNames: ({ facadeModuleId, name }) => facadeModuleId ? (
145
- // Keep the original extension, add .js after it
146
- `${addExtension(name, extname(facadeModuleId))}.js`
147
- ) : addExtension(name),
148
- preserveModules: true,
149
- preserveModulesRoot: options.client?.input?.dir ?? "./src/client/"
146
+ dir: options.client?.output ?? "./javascript/client/"
150
147
  },
151
148
  external,
152
149
  plugins: [
@@ -197,6 +194,10 @@ function jahia(options = {}) {
197
194
  )
198
195
  },
199
196
  external: [...external, "@jahia/javascript-modules-library"],
197
+ treeshake: {
198
+ // Manually mark useEffect as pure to have it removed from the SSR bundle
199
+ manualPureFunctions: ["useEffect"]
200
+ },
200
201
  plugins: [
201
202
  multiEntry({
202
203
  exports: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jahia/vite-plugin",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com:Jahia/javascript-modules.git",
package/pom.xml CHANGED
@@ -3,7 +3,7 @@
3
3
  <parent>
4
4
  <artifactId>javascript-modules</artifactId>
5
5
  <groupId>org.jahia.modules</groupId>
6
- <version>0.5.3</version>
6
+ <version>0.5.5</version>
7
7
  </parent>
8
8
  <artifactId>vite-plugin</artifactId>
9
9
  <name>Vite plugin for Jahia</name>
@@ -29,11 +29,10 @@
29
29
  <executions>
30
30
  <!-- Executions bound on the "initialize" phase (executed in order of declaration): -->
31
31
  <execution>
32
- <id>install node, yarn and npm</id>
32
+ <id>install node and yarn</id>
33
33
  <phase>initialize</phase>
34
34
  <goals>
35
35
  <goal>install-node-and-yarn</goal>
36
- <goal>install-node-and-npm</goal>
37
36
  </goals>
38
37
  </execution>
39
38
  <execution>
@@ -69,13 +68,13 @@
69
68
  <executions>
70
69
  <!-- Keep the package.json in sync with the maven version -->
71
70
  <execution>
72
- <id>bump-version</id>
71
+ <id>sync-version</id>
73
72
  <phase>process-resources</phase>
74
73
  <goals>
75
74
  <goal>yarn</goal>
76
75
  </goals>
77
76
  <configuration>
78
- <arguments>node sync-version.js ${project.version}</arguments>
77
+ <arguments>node ../.m2/sync-version.js ${project.version}</arguments>
79
78
  </configuration>
80
79
  </execution>
81
80
  </executions>
package/src/index.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import multiEntry from "@rollup/plugin-multi-entry";
2
- import { addExtension } from "@rollup/pluginutils";
3
2
  import sharedLibs from "javascript-modules-engine/shared-libs.mjs";
4
- import { extname } from "node:path";
3
+ import path from "node:path";
5
4
  import { styleText } from "node:util";
6
5
  import type { Plugin } from "rollup";
7
6
  import { globSync } from "tinyglobby";
@@ -94,10 +93,8 @@ export default function jahia(
94
93
  watchCallback?: () => void | Promise<void>;
95
94
  } = {},
96
95
  ): PluginOption {
97
- const clientEntries = globSync(options.client?.input?.glob ?? "**/*.jsx", {
98
- cwd: options.client?.input?.dir ?? "./src/client/",
99
- absolute: true,
100
- });
96
+ const clientBaseDir = options.client?.input?.dir ?? "./src/client/";
97
+ const clientEntries = globSync(options.client?.input?.glob ?? "**/*.jsx", { cwd: clientBaseDir });
101
98
 
102
99
  if (clientEntries.length === 0) {
103
100
  console.warn(
@@ -122,31 +119,27 @@ export default function jahia(
122
119
  */
123
120
  config(config) {
124
121
  // Mutate the configuration to set base settings if they are not already set
125
- // Build all environments https://vite.dev/guide/api-environment-frameworks.html#environments-during-build
126
- config.builder ??= { sharedConfigBuild: true };
127
-
128
122
  // Enable the modern JSX runtime
129
123
  config.esbuild ??= { jsx: "automatic" };
130
124
 
131
125
  return {
126
+ // Build all environments https://vite.dev/guide/api-environment-frameworks.html#environments-during-build
127
+ builder: { sharedConfigBuild: true },
128
+ // Enforce bundling of all dependencies
129
+ ssr: { noExternal: true },
130
+ // Define the environments (client and ssr)
132
131
  environments: {
133
132
  client: {
134
133
  build: {
135
134
  lib: {
136
- // Single entry point for the client, all other files must be imported in this one
137
- entry: clientEntries,
135
+ entry: Object.fromEntries(
136
+ clientEntries.map((file) => [file, path.join(clientBaseDir, file)]),
137
+ ),
138
138
  formats: ["es"],
139
139
  },
140
140
  rollupOptions: {
141
141
  output: {
142
142
  dir: options.client?.output ?? "./javascript/client/",
143
- entryFileNames: ({ facadeModuleId, name }) =>
144
- facadeModuleId
145
- ? // Keep the original extension, add .js after it
146
- `${addExtension(name, extname(facadeModuleId))}.js`
147
- : addExtension(name),
148
- preserveModules: true,
149
- preserveModulesRoot: options.client?.input?.dir ?? "./src/client/",
150
143
  },
151
144
  external,
152
145
  plugins: [
@@ -197,6 +190,10 @@ export default function jahia(
197
190
  ),
198
191
  },
199
192
  external: [...external, "@jahia/javascript-modules-library"],
193
+ treeshake: {
194
+ // Manually mark useEffect as pure to have it removed from the SSR bundle
195
+ manualPureFunctions: ["useEffect"],
196
+ },
200
197
  plugins: [
201
198
  multiEntry({
202
199
  exports: false,
package/node/npm DELETED
@@ -1,65 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- # This is used by the Node.js installer, which expects the cygwin/mingw
4
- # shell script to already be present in the npm dependency folder.
5
-
6
- (set -o igncr) 2>/dev/null && set -o igncr; # cygwin encoding fix
7
-
8
- basedir=`dirname "$0"`
9
-
10
- case `uname` in
11
- *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
12
- esac
13
-
14
- if [ `uname` = 'Linux' ] && type wslpath &>/dev/null ; then
15
- IS_WSL="true"
16
- fi
17
-
18
- function no_node_dir {
19
- # if this didn't work, then everything else below will fail
20
- echo "Could not determine Node.js install directory" >&2
21
- exit 1
22
- }
23
-
24
- NODE_EXE="$basedir/node.exe"
25
- if ! [ -x "$NODE_EXE" ]; then
26
- NODE_EXE="$basedir/node"
27
- fi
28
- if ! [ -x "$NODE_EXE" ]; then
29
- NODE_EXE=node
30
- fi
31
-
32
- # this path is passed to node.exe, so it needs to match whatever
33
- # kind of paths Node.js thinks it's using, typically win32 paths.
34
- CLI_BASEDIR="$("$NODE_EXE" -p 'require("path").dirname(process.execPath)' 2> /dev/null)"
35
- if [ $? -ne 0 ]; then
36
- # this fails under WSL 1 so add an additional message. we also suppress stderr above
37
- # because the actual error raised is not helpful. in WSL 1 node.exe cannot handle
38
- # output redirection properly. See https://github.com/microsoft/WSL/issues/2370
39
- if [ "$IS_WSL" == "true" ]; then
40
- echo "WSL 1 is not supported. Please upgrade to WSL 2 or above." >&2
41
- fi
42
- no_node_dir
43
- fi
44
- NPM_PREFIX_JS="$CLI_BASEDIR/node_modules/npm/bin/npm-prefix.js"
45
- NPM_CLI_JS="$CLI_BASEDIR/node_modules/npm/bin/npm-cli.js"
46
- NPM_PREFIX=`"$NODE_EXE" "$NPM_PREFIX_JS"`
47
- if [ $? -ne 0 ]; then
48
- no_node_dir
49
- fi
50
- NPM_PREFIX_NPM_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npm-cli.js"
51
-
52
- # a path that will fail -f test on any posix bash
53
- NPM_WSL_PATH="/.."
54
-
55
- # WSL can run Windows binaries, so we have to give it the win32 path
56
- # however, WSL bash tests against posix paths, so we need to construct that
57
- # to know if npm is installed globally.
58
- if [ "$IS_WSL" == "true" ]; then
59
- NPM_WSL_PATH=`wslpath "$NPM_PREFIX_NPM_CLI_JS"`
60
- fi
61
- if [ -f "$NPM_PREFIX_NPM_CLI_JS" ] || [ -f "$NPM_WSL_PATH" ]; then
62
- NPM_CLI_JS="$NPM_PREFIX_NPM_CLI_JS"
63
- fi
64
-
65
- "$NODE_EXE" "$NPM_CLI_JS" "$@"
package/node/npm.cmd DELETED
@@ -1,20 +0,0 @@
1
- :: Created by npm, please don't edit manually.
2
- @ECHO OFF
3
-
4
- SETLOCAL
5
-
6
- SET "NODE_EXE=%~dp0\node.exe"
7
- IF NOT EXIST "%NODE_EXE%" (
8
- SET "NODE_EXE=node"
9
- )
10
-
11
- SET "NPM_PREFIX_JS=%~dp0\node_modules\npm\bin\npm-prefix.js"
12
- SET "NPM_CLI_JS=%~dp0\node_modules\npm\bin\npm-cli.js"
13
- FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_PREFIX_JS%"') DO (
14
- SET "NPM_PREFIX_NPM_CLI_JS=%%F\node_modules\npm\bin\npm-cli.js"
15
- )
16
- IF EXIST "%NPM_PREFIX_NPM_CLI_JS%" (
17
- SET "NPM_CLI_JS=%NPM_PREFIX_NPM_CLI_JS%"
18
- )
19
-
20
- "%NODE_EXE%" "%NPM_CLI_JS%" %*
package/node/npx DELETED
@@ -1,65 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- # This is used by the Node.js installer, which expects the cygwin/mingw
4
- # shell script to already be present in the npm dependency folder.
5
-
6
- (set -o igncr) 2>/dev/null && set -o igncr; # cygwin encoding fix
7
-
8
- basedir=`dirname "$0"`
9
-
10
- case `uname` in
11
- *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
12
- esac
13
-
14
- if [ `uname` = 'Linux' ] && type wslpath &>/dev/null ; then
15
- IS_WSL="true"
16
- fi
17
-
18
- function no_node_dir {
19
- # if this didn't work, then everything else below will fail
20
- echo "Could not determine Node.js install directory" >&2
21
- exit 1
22
- }
23
-
24
- NODE_EXE="$basedir/node.exe"
25
- if ! [ -x "$NODE_EXE" ]; then
26
- NODE_EXE="$basedir/node"
27
- fi
28
- if ! [ -x "$NODE_EXE" ]; then
29
- NODE_EXE=node
30
- fi
31
-
32
- # this path is passed to node.exe, so it needs to match whatever
33
- # kind of paths Node.js thinks it's using, typically win32 paths.
34
- CLI_BASEDIR="$("$NODE_EXE" -p 'require("path").dirname(process.execPath)' 2> /dev/null)"
35
- if [ $? -ne 0 ]; then
36
- # this fails under WSL 1 so add an additional message. we also suppress stderr above
37
- # because the actual error raised is not helpful. in WSL 1 node.exe cannot handle
38
- # output redirection properly. See https://github.com/microsoft/WSL/issues/2370
39
- if [ "$IS_WSL" == "true" ]; then
40
- echo "WSL 1 is not supported. Please upgrade to WSL 2 or above." >&2
41
- fi
42
- no_node_dir
43
- fi
44
- NPM_PREFIX_JS="$CLI_BASEDIR/node_modules/npm/bin/npm-prefix.js"
45
- NPX_CLI_JS="$CLI_BASEDIR/node_modules/npm/bin/npx-cli.js"
46
- NPM_PREFIX=`"$NODE_EXE" "$NPM_PREFIX_JS"`
47
- if [ $? -ne 0 ]; then
48
- no_node_dir
49
- fi
50
- NPM_PREFIX_NPX_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npx-cli.js"
51
-
52
- # a path that will fail -f test on any posix bash
53
- NPX_WSL_PATH="/.."
54
-
55
- # WSL can run Windows binaries, so we have to give it the win32 path
56
- # however, WSL bash tests against posix paths, so we need to construct that
57
- # to know if npm is installed globally.
58
- if [ "$IS_WSL" == "true" ]; then
59
- NPX_WSL_PATH=`wslpath "$NPM_PREFIX_NPX_CLI_JS"`
60
- fi
61
- if [ -f "$NPM_PREFIX_NPX_CLI_JS" ] || [ -f "$NPX_WSL_PATH" ]; then
62
- NPX_CLI_JS="$NPM_PREFIX_NPX_CLI_JS"
63
- fi
64
-
65
- "$NODE_EXE" "$NPX_CLI_JS" "$@"
package/node/npx.cmd DELETED
@@ -1,20 +0,0 @@
1
- :: Created by npm, please don't edit manually.
2
- @ECHO OFF
3
-
4
- SETLOCAL
5
-
6
- SET "NODE_EXE=%~dp0\node.exe"
7
- IF NOT EXIST "%NODE_EXE%" (
8
- SET "NODE_EXE=node"
9
- )
10
-
11
- SET "NPM_PREFIX_JS=%~dp0\node_modules\npm\bin\npm-prefix.js"
12
- SET "NPX_CLI_JS=%~dp0\node_modules\npm\bin\npx-cli.js"
13
- FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_PREFIX_JS%"') DO (
14
- SET "NPM_PREFIX_NPX_CLI_JS=%%F\node_modules\npm\bin\npx-cli.js"
15
- )
16
- IF EXIST "%NPM_PREFIX_NPX_CLI_JS%" (
17
- SET "NPX_CLI_JS=%NPM_PREFIX_NPX_CLI_JS%"
18
- )
19
-
20
- "%NODE_EXE%" "%NPX_CLI_JS%" %*
package/sync-version.js DELETED
@@ -1,16 +0,0 @@
1
- /**
2
- * @module
3
- *
4
- * Updates the package.json version, used during the maven release process.
5
- *
6
- * Usage: node sync-version.js 1.2.3
7
- *
8
- * @see {@link ./pom.xml}
9
- */
10
-
11
- import fs from "node:fs";
12
-
13
- const updated = fs
14
- .readFileSync("package.json", "utf8")
15
- .replace(/"version": ".+"/, `"version": ${JSON.stringify(process.argv[2])}`);
16
- fs.writeFileSync("package.json", updated);