@rstest/adapter-rspack 0.2.0 → 0.10.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present ByteDance, Inc. and its affiliates.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -29,9 +29,11 @@ export interface WithRspackConfigOptions {
29
29
  */
30
30
  modifyRspackConfig?: (config: RspackOptions) => RspackOptions;
31
31
  }
32
- export declare function toRstestConfig({ rspackConfig, configName, modifyRspackConfig, }: {
32
+ export declare function toRstestConfig({ rspackConfig, configName, configPath, cwd, modifyRspackConfig, }: {
33
33
  rspackConfig: RspackOptions;
34
34
  configName?: RspackConfigName;
35
+ configPath?: string;
36
+ cwd?: string;
35
37
  modifyRspackConfig?: (config: RspackOptions) => RspackOptions;
36
38
  }): ExtendConfig;
37
39
  export declare function withRspackConfig(options?: WithRspackConfigOptions): ExtendConfigFn;
package/dist/index.js CHANGED
@@ -28,6 +28,39 @@ const normalizeTargets = (target)=>{
28
28
  };
29
29
  const isNodeTarget = (targets)=>targets.some((target)=>'async-node' === target || target.startsWith('node'));
30
30
  const isHtmlRspackPlugin = (plugin)=>plugin && plugin.constructor ? 'HtmlRspackPlugin' === plugin.constructor.name : false;
31
+ const isPersistentCacheConfig = (cache)=>'object' == typeof cache && cache?.type === 'persistent';
32
+ const getCachePath = ({ cachePath, root })=>{
33
+ if (node_path.isAbsolute(cachePath)) return node_path.normalize(cachePath);
34
+ return root ? node_path.normalize(node_path.resolve(root, cachePath)) : cachePath;
35
+ };
36
+ const getCacheRoot = (rspackConfig, cwd)=>{
37
+ const { context } = rspackConfig;
38
+ if (!context) return cwd;
39
+ return node_path.isAbsolute(context) ? context : node_path.resolve(cwd ?? process.cwd(), context);
40
+ };
41
+ const updateCacheConfig = ({ cache, configPath, root })=>{
42
+ if (void 0 === cache) return;
43
+ if (false === cache || 'object' == typeof cache && cache?.type === 'memory') return false;
44
+ if (!isPersistentCacheConfig(cache)) return;
45
+ const buildDependencies = cache.buildDependencies?.map((dependency)=>getCachePath({
46
+ cachePath: dependency,
47
+ root
48
+ }));
49
+ const nextBuildDependencies = configPath ? Array.from(new Set([
50
+ ...buildDependencies || [],
51
+ node_path.normalize(configPath)
52
+ ])) : buildDependencies;
53
+ return {
54
+ cacheDirectory: cache.storage?.directory ? getCachePath({
55
+ cachePath: cache.storage.directory,
56
+ root
57
+ }) : void 0,
58
+ cacheDigest: cache.version ? [
59
+ cache.version
60
+ ] : void 0,
61
+ buildDependencies: nextBuildDependencies
62
+ };
63
+ };
31
64
  const buildRspackToolConfig = (rspackConfig)=>{
32
65
  const { lazyCompilation: _lazy, ...restConfig } = rspackConfig;
33
66
  return (config)=>{
@@ -80,7 +113,7 @@ const buildRspackToolConfig = (rspackConfig)=>{
80
113
  ...config.externalsPresets || {},
81
114
  ...restConfig.externalsPresets
82
115
  };
83
- if (void 0 !== restConfig.cache) nextConfig.cache = restConfig.cache;
116
+ if (void 0 !== restConfig.cache && !isPersistentCacheConfig(restConfig.cache)) nextConfig.cache = restConfig.cache;
84
117
  return nextConfig;
85
118
  };
86
119
  };
@@ -108,9 +141,12 @@ const loadRspackConfig = async (options)=>{
108
141
  env: options.env,
109
142
  nodeEnv: options.nodeEnv
110
143
  });
111
- return config;
144
+ return {
145
+ config: config,
146
+ configFile
147
+ };
112
148
  };
113
- function toRstestConfig({ rspackConfig, configName, modifyRspackConfig }) {
149
+ function toRstestConfig({ rspackConfig, configName, configPath, cwd, modifyRspackConfig }) {
114
150
  const finalConfig = modifyRspackConfig ? modifyRspackConfig(rspackConfig) : rspackConfig;
115
151
  const targets = normalizeTargets(finalConfig.target);
116
152
  const testEnvironment = isNodeTarget(targets) ? 'node' : 'happy-dom';
@@ -119,6 +155,11 @@ function toRstestConfig({ rspackConfig, configName, modifyRspackConfig }) {
119
155
  const output = void 0 !== outputModule ? {
120
156
  module: outputModule
121
157
  } : void 0;
158
+ const buildCache = updateCacheConfig({
159
+ cache: finalConfig.cache,
160
+ configPath,
161
+ root: getCacheRoot(finalConfig, cwd)
162
+ });
122
163
  const tsConfig = finalConfig.resolve?.tsConfig;
123
164
  const tsconfigPath = 'string' == typeof tsConfig ? tsConfig : tsConfig?.configFile;
124
165
  const source = tsconfigPath ? {
@@ -135,6 +176,12 @@ function toRstestConfig({ rspackConfig, configName, modifyRspackConfig }) {
135
176
  ...resolve ? {
136
177
  resolve
137
178
  } : {},
179
+ forceRerunTriggers: configPath ? [
180
+ node_path.normalize(configPath)
181
+ ] : void 0,
182
+ performance: {
183
+ buildCache
184
+ },
138
185
  plugins: [
139
186
  {
140
187
  name: 'remove-rsbuild-css',
@@ -154,12 +201,16 @@ function toRstestConfig({ rspackConfig, configName, modifyRspackConfig }) {
154
201
  }
155
202
  function withRspackConfig(options = {}) {
156
203
  return async ()=>{
157
- const config = await loadRspackConfig(options);
158
- if (!config) return {};
204
+ const loaded = await loadRspackConfig(options);
205
+ if (!loaded) return {};
206
+ const { config, configFile } = loaded;
159
207
  const selectedConfig = selectRspackConfig(config, options.configName);
208
+ const cwd = options.cwd ?? process.cwd();
160
209
  return toRstestConfig({
161
210
  rspackConfig: selectedConfig,
162
211
  configName: options.configName,
212
+ configPath: configFile,
213
+ cwd,
163
214
  modifyRspackConfig: options.modifyRspackConfig
164
215
  });
165
216
  };
package/package.json CHANGED
@@ -1,53 +1,53 @@
1
1
  {
2
2
  "name": "@rstest/adapter-rspack",
3
- "version": "0.2.0",
3
+ "version": "0.10.0",
4
4
  "description": "Rstest adapter for rspack configuration",
5
+ "keywords": [
6
+ "rstest",
7
+ "rspack",
8
+ "adapter",
9
+ "configuration"
10
+ ],
11
+ "bugs": {
12
+ "url": "https://github.com/web-infra-dev/rstest/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/web-infra-dev/rstest",
17
+ "directory": "packages/adapter-rspack"
18
+ },
19
+ "license": "MIT",
5
20
  "type": "module",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
21
  "exports": {
9
22
  ".": {
10
- "import": "./dist/index.js",
11
- "types": "./dist/index.d.ts"
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js"
12
25
  }
13
26
  },
27
+ "main": "dist/index.js",
28
+ "types": "dist/index.d.ts",
14
29
  "files": [
15
30
  "dist"
16
31
  ],
17
- "scripts": {
18
- "build": "rslib build",
19
- "dev": "rslib build --watch",
20
- "test": "rstest",
21
- "typecheck": "tsc --noEmit"
32
+ "devDependencies": {
33
+ "@rslib/core": "0.21.4",
34
+ "@rspack/cli": "2.0.3",
35
+ "@rspack/core": "2.0.3",
36
+ "@rstest/core": "0.10.0",
37
+ "@rstest/tsconfig": "0.0.1"
22
38
  },
23
- "keywords": [
24
- "rstest",
25
- "rspack",
26
- "adapter",
27
- "configuration"
28
- ],
29
- "license": "MIT",
30
39
  "peerDependencies": {
31
40
  "@rspack/cli": ">=2.0.0-0",
32
41
  "@rspack/core": ">=2.0.0-0",
33
- "@rstest/core": ">=0.7.7"
34
- },
35
- "devDependencies": {
36
- "@rspack/cli": "2.0.0-beta.6",
37
- "@rspack/core": "2.0.0-beta.6",
38
- "@rslib/core": "0.20.0",
39
- "@rstest/core": "workspace:*",
40
- "@rstest/tsconfig": "workspace:*"
42
+ "@rstest/core": "^0.10.0"
41
43
  },
42
44
  "publishConfig": {
43
45
  "access": "public"
44
46
  },
45
- "bugs": {
46
- "url": "https://github.com/web-infra-dev/rstest/issues"
47
- },
48
- "repository": {
49
- "type": "git",
50
- "url": "https://github.com/web-infra-dev/rstest",
51
- "directory": "packages/adapter-rspack"
47
+ "scripts": {
48
+ "build": "rslib build",
49
+ "dev": "rslib build --watch",
50
+ "test": "rstest",
51
+ "typecheck": "pnpm -w exec tsc --noEmit -p packages/adapter-rspack/tsconfig.json"
52
52
  }
53
- }
53
+ }