stylex-webpack 0.4.5 → 0.4.6

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/dist/index.js +40 -40
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ var path = require('node:path');
5
5
  var process = require('node:process');
6
6
  var identity = require('foxts/identity');
7
7
 
8
- var version = "0.4.5";
8
+ var version = "0.4.6";
9
9
 
10
10
  const PLUGIN_NAME = 'stylex';
11
11
  const VIRTUAL_ENTRYPOINT_CSS_PATH = require.resolve('./stylex.css');
@@ -120,11 +120,37 @@ class StyleXPlugin {
120
120
  });
121
121
  }
122
122
  });
123
- compilation.hooks.processAssets.tapPromise({
124
- name: PLUGIN_NAME,
125
- stage: Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS
126
- }, async (assets)=>{
127
- compilation.modules.forEach((mod)=>{
123
+ /**
124
+ * Next.js call webpack compiler through "runCompiler": https://github.com/vercel/next.js/blob/c0c75e4aaa8ece2c9e789e2e3f150d7487b60bbc/packages/next/src/build/compiler.ts#L39
125
+ *
126
+ * The "runCompiler" funtion is invoked by "webpackBuildImpl" function: https://github.com/vercel/next.js/blob/ad6907a8a37e930639af071203f4ce49a5d69ee5/packages/next/src/build/webpack-build/impl.ts#L203
127
+ *
128
+ * The "webpackBuildImpl" function accepts "compilerName" parameter, and is invoked by "webpackBuild" function: https://github.com/vercel/next.js/blob/c0c75e4aaa8ece2c9e789e2e3f150d7487b60bbc/packages/next/src/build/webpack-build/index.ts#L124
129
+ * When build worker is enabled, the "compilerName" parameter is set to either "client", "server" or "edge-server". If build worker is disabled,
130
+ * the "compilerName" parameter is always "null".
131
+ *
132
+ * When build worker is disabled, the multi-stage build is managed by "webpackBuildImpl" function itself: https://github.com/vercel/next.js/blob/ad6907a8a37e930639af071203f4ce49a5d69ee5/packages/next/src/build/webpack-build/impl.ts#L203
133
+ * It will first run "server" compiler, then "edge-server" compiler, and finally "client" compiler.
134
+ *
135
+ * The "webpackBuildImpl" function is invoked by "webpackBuild" function: https://github.com/vercel/next.js/blob/c0c75e4aaa8ece2c9e789e2e3f150d7487b60bbc/packages/next/src/build/webpack-build/index.ts#L124
136
+ *
137
+ * If build worker is enabled, the multi-stage build is managed by the build entrypoint, and the "client", "server" and "edge-server" compilerName
138
+ * is passed to "webpackBuildImpl" through "webpackBuild" function:
139
+ * https://github.com/vercel/next.js/blob/c0c75e4aaa8ece2c9e789e2e3f150d7487b60bbc/packages/next/src/build/index.ts#L905
140
+ * https://github.com/vercel/next.js/blob/c0c75e4aaa8ece2c9e789e2e3f150d7487b60bbc/packages/next/src/build/index.ts#L1796
141
+ *
142
+ * Note that, if a custom webpack config is provided, Next.js will always disable build worker: https://github.com/vercel/next.js/blob/c0c75e4aaa8ece2c9e789e2e3f150d7487b60bbc/packages/next/src/build/index.ts#L1723
143
+ * We will not take that as an assumption. We already overwrite "nextConfig.experimental.webpackBuildWorker" to false in the Next.js plugin.
144
+ *
145
+ * Now all compiler instances are running in the same process, we can use a global variable to track stylex rules from different compilers.
146
+ *
147
+ * Back to "runCompiler". "runCompiler" accepts webpack configurations which is created by "getBaseWebpackConfig" function: https://github.com/vercel/next.js/blob/ad6907a8a37e930639af071203f4ce49a5d69ee5/packages/next/src/build/webpack-build/impl.ts#L128
148
+ *
149
+ * Inside "getBaseWebpackConfig" function, there is a "buildConfiguration" function: https://github.com/vercel/next.js/blob/ad6907a8a37e930639af071203f4ce49a5d69ee5/packages/next/src/build/webpack-config.ts#L2464
150
+ * Inside "buildConfiguration" function there is a curried "base" function: https://github.com/vercel/next.js/blob/c0c75e4aaa8ece2c9e789e2e3f150d7487b60bbc/packages/next/src/build/webpack/config/index.ts#L73
151
+ * Inside the "base" function, the compiler name is attached to the webpack configuration: https://github.com/vercel/next.js/blob/c0c75e4aaa8ece2c9e789e2e3f150d7487b60bbc/packages/next/src/build/webpack/config/blocks/base.ts#L24
152
+ */ compilation.hooks.finishModules.tap(PLUGIN_NAME, (modules)=>{
153
+ for (const mod of modules){
128
154
  if (mod.buildInfo && BUILD_INFO_STYLEX_KEY in mod.buildInfo) {
129
155
  const stylexBuildInfo = mod.buildInfo[BUILD_INFO_STYLEX_KEY];
130
156
  if (typeof stylexBuildInfo === 'object' && stylexBuildInfo != null && 'resourcePath' in stylexBuildInfo && 'stylexRules' in stylexBuildInfo && typeof stylexBuildInfo.resourcePath === 'string') {
@@ -132,38 +158,14 @@ class StyleXPlugin {
132
158
  this.stylexRules.set(stylexBuildInfo.resourcePath, stylexBuildInfo.stylexRules);
133
159
  }
134
160
  }
135
- });
161
+ }
162
+ });
163
+ compilation.hooks.processAssets.tapPromise({
164
+ name: PLUGIN_NAME,
165
+ stage: Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS
166
+ }, async (assets)=>{
136
167
  if (this.loaderOption.nextjsMode && this.loaderOption.nextjsAppRouterMode && isNextJsCompilerName(compiler.name)) {
137
- /**
138
- * Next.js call webpack compiler through "runCompiler": https://github.com/vercel/next.js/blob/c0c75e4aaa8ece2c9e789e2e3f150d7487b60bbc/packages/next/src/build/compiler.ts#L39
139
- *
140
- * The "runCompiler" funtion is invoked by "webpackBuildImpl" function: https://github.com/vercel/next.js/blob/ad6907a8a37e930639af071203f4ce49a5d69ee5/packages/next/src/build/webpack-build/impl.ts#L203
141
- *
142
- * The "webpackBuildImpl" function accepts "compilerName" parameter, and is invoked by "webpackBuild" function: https://github.com/vercel/next.js/blob/c0c75e4aaa8ece2c9e789e2e3f150d7487b60bbc/packages/next/src/build/webpack-build/index.ts#L124
143
- * When build worker is enabled, the "compilerName" parameter is set to either "client", "server" or "edge-server". If build worker is disabled,
144
- * the "compilerName" parameter is always "null".
145
- *
146
- * When build worker is disabled, the multi-stage build is managed by "webpackBuildImpl" function itself: https://github.com/vercel/next.js/blob/ad6907a8a37e930639af071203f4ce49a5d69ee5/packages/next/src/build/webpack-build/impl.ts#L203
147
- * It will first run "server" compiler, then "edge-server" compiler, and finally "client" compiler.
148
- *
149
- * The "webpackBuildImpl" function is invoked by "webpackBuild" function: https://github.com/vercel/next.js/blob/c0c75e4aaa8ece2c9e789e2e3f150d7487b60bbc/packages/next/src/build/webpack-build/index.ts#L124
150
- *
151
- * If build worker is enabled, the multi-stage build is managed by the build entrypoint, and the "client", "server" and "edge-server" compilerName
152
- * is passed to "webpackBuildImpl" through "webpackBuild" function:
153
- * https://github.com/vercel/next.js/blob/c0c75e4aaa8ece2c9e789e2e3f150d7487b60bbc/packages/next/src/build/index.ts#L905
154
- * https://github.com/vercel/next.js/blob/c0c75e4aaa8ece2c9e789e2e3f150d7487b60bbc/packages/next/src/build/index.ts#L1796
155
- *
156
- * Note that, if a custom webpack config is provided, Next.js will always disable build worker: https://github.com/vercel/next.js/blob/c0c75e4aaa8ece2c9e789e2e3f150d7487b60bbc/packages/next/src/build/index.ts#L1723
157
- * We will not take that as an assumption. We already overwrite "nextConfig.experimental.webpackBuildWorker" to false in the Next.js plugin.
158
- *
159
- * Now all compiler instances are running in the same process, we can use a global variable to track stylex rules from different compilers.
160
- *
161
- * Back to "runCompiler". "runCompiler" accepts webpack configurations which is created by "getBaseWebpackConfig" function: https://github.com/vercel/next.js/blob/ad6907a8a37e930639af071203f4ce49a5d69ee5/packages/next/src/build/webpack-build/impl.ts#L128
162
- *
163
- * Inside "getBaseWebpackConfig" function, there is a "buildConfiguration" function: https://github.com/vercel/next.js/blob/ad6907a8a37e930639af071203f4ce49a5d69ee5/packages/next/src/build/webpack-config.ts#L2464
164
- * Inside "buildConfiguration" function there is a curried "base" function: https://github.com/vercel/next.js/blob/c0c75e4aaa8ece2c9e789e2e3f150d7487b60bbc/packages/next/src/build/webpack/config/index.ts#L73
165
- * Inside the "base" function, the compiler name is attached to the webpack configuration: https://github.com/vercel/next.js/blob/c0c75e4aaa8ece2c9e789e2e3f150d7487b60bbc/packages/next/src/build/webpack/config/blocks/base.ts#L24
166
- */ if (compiler.name === NEXTJS_COMPILER_NAMES.server || compiler.name === NEXTJS_COMPILER_NAMES.edgeServer) {
168
+ if (compiler.name === NEXTJS_COMPILER_NAMES.server || compiler.name === NEXTJS_COMPILER_NAMES.edgeServer) {
167
169
  var _globalThis;
168
170
  ((_globalThis = globalThis).__stylex_nextjs_global_registry__ ?? (_globalThis.__stylex_nextjs_global_registry__ = new Map())).set(compiler.name, this.stylexRules);
169
171
  // we don't need to do anything more in server/edge compiler, no CSS generation is needed
@@ -176,9 +178,7 @@ class StyleXPlugin {
176
178
  // now we merge all collected rules from other compilers
177
179
  globalRegistry.forEach((rules)=>{
178
180
  rules.forEach((rule, resourcePath)=>{
179
- if (!this.stylexRules.has(resourcePath)) {
180
- this.stylexRules.set(resourcePath, rule);
181
- }
181
+ this.stylexRules.set(resourcePath, rule);
182
182
  });
183
183
  });
184
184
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stylex-webpack",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "description": "The another Webpack Plugin for Facebook's StyleX",
5
5
  "homepage": "https://github.com/SukkaW/style9-webpack#readme",
6
6
  "repository": {