rsbuild-plugin-arethetypeswrong 0.2.0 → 0.3.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/dist/453.js CHANGED
@@ -1,26 +1,185 @@
1
- const problemFlags = {
2
- NoResolution: "no-resolution",
3
- UntypedResolution: "untyped-resolution",
4
- FalseCJS: "false-cjs",
5
- FalseESM: "false-esm",
6
- CJSResolvesToESM: "cjs-resolves-to-esm",
7
- FallbackCondition: "fallback-condition",
8
- CJSOnlyExportsDefault: "cjs-only-exports-default",
9
- NamedExports: "named-exports",
10
- FalseExportDefault: "false-export-default",
11
- MissingExportEquals: "missing-export-equals",
12
- UnexpectedModuleSyntax: "unexpected-module-syntax",
13
- InternalResolutionError: "internal-resolution-error"
14
- };
15
- const resolutionKinds = {
16
- node10: "node10",
17
- "node16-cjs": "node16 (from CJS)",
18
- "node16-esm": "node16 (from ESM)",
19
- bundler: "bundler"
20
- };
21
- const moduleKinds = {
22
- 1: "(CJS)",
23
- 99: "(ESM)",
24
- "": ""
25
- };
26
- export { moduleKinds, problemFlags, resolutionKinds };
1
+ import node_fs from "node:fs";
2
+ import node_path from "node:path";
3
+ import { logger } from "@rsbuild/core";
4
+ import { createRequire as __rspack_createRequire } from "node:module";
5
+ const __rspack_createRequire_require = __rspack_createRequire(import.meta.url);
6
+ var __webpack_modules__ = {};
7
+ var __webpack_module_cache__ = {};
8
+ function __webpack_require__(moduleId) {
9
+ var cachedModule = __webpack_module_cache__[moduleId];
10
+ if (void 0 !== cachedModule) return cachedModule.exports;
11
+ var module = __webpack_module_cache__[moduleId] = {
12
+ exports: {}
13
+ };
14
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
15
+ return module.exports;
16
+ }
17
+ __webpack_require__.m = __webpack_modules__;
18
+ (()=>{
19
+ __webpack_require__.n = (module)=>{
20
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
21
+ __webpack_require__.d(getter, {
22
+ a: getter
23
+ });
24
+ return getter;
25
+ };
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.d = (exports, definition)=>{
29
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
30
+ enumerable: true,
31
+ get: definition[key]
32
+ });
33
+ };
34
+ })();
35
+ (()=>{
36
+ __webpack_require__.add = function(modules) {
37
+ Object.assign(__webpack_require__.m, modules);
38
+ };
39
+ })();
40
+ var __webpack_require__temp = __webpack_require__;
41
+ (()=>{
42
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
43
+ })();
44
+ (()=>{
45
+ var installedChunks = {
46
+ 410: 0,
47
+ 453: 0
48
+ };
49
+ var installChunk = (data)=>{
50
+ var __rspack_esm_ids = data.__rspack_esm_ids;
51
+ var __webpack_modules__ = data.__webpack_modules__;
52
+ var __rspack_esm_runtime = data.__rspack_esm_runtime;
53
+ var moduleId, chunkId, i = 0;
54
+ for(moduleId in __webpack_modules__)if (__webpack_require__.o(__webpack_modules__, moduleId)) __webpack_require__.m[moduleId] = __webpack_modules__[moduleId];
55
+ if (__rspack_esm_runtime) __rspack_esm_runtime(__webpack_require__);
56
+ for(; i < __rspack_esm_ids.length; i++){
57
+ chunkId = __rspack_esm_ids[i];
58
+ if (__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) installedChunks[chunkId][0]();
59
+ installedChunks[__rspack_esm_ids[i]] = 0;
60
+ }
61
+ };
62
+ __webpack_require__.C = installChunk;
63
+ })();
64
+ __webpack_require__.add({
65
+ "module?f4c0" (module) {
66
+ module.exports = __rspack_createRequire_require("module");
67
+ },
68
+ os (module) {
69
+ module.exports = __rspack_createRequire_require("os");
70
+ },
71
+ util (module) {
72
+ module.exports = __rspack_createRequire_require("util");
73
+ }
74
+ });
75
+ function _ts_add_disposable_resource(env, value, async) {
76
+ if (null != value) {
77
+ if ("object" != typeof value && "function" != typeof value) throw new TypeError("Object expected.");
78
+ var dispose, inner;
79
+ if (async) {
80
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
81
+ dispose = value[Symbol.asyncDispose];
82
+ }
83
+ if (void 0 === dispose) {
84
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
85
+ dispose = value[Symbol.dispose];
86
+ if (async) inner = dispose;
87
+ }
88
+ if ("function" != typeof dispose) throw new TypeError("Object not disposable.");
89
+ if (inner) dispose = function() {
90
+ try {
91
+ inner.call(this);
92
+ } catch (e) {
93
+ return Promise.reject(e);
94
+ }
95
+ };
96
+ env.stack.push({
97
+ value: value,
98
+ dispose: dispose,
99
+ async: async
100
+ });
101
+ } else if (async) env.stack.push({
102
+ async: true
103
+ });
104
+ return value;
105
+ }
106
+ function src_ts_dispose_resources(env) {
107
+ var _SuppressedError = "function" == typeof SuppressedError ? SuppressedError : function(error, suppressed, message) {
108
+ var e = new Error(message);
109
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
110
+ };
111
+ return (src_ts_dispose_resources = function(env) {
112
+ function fail(e) {
113
+ env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
114
+ env.hasError = true;
115
+ }
116
+ var r, s = 0;
117
+ function next() {
118
+ while(r = env.stack.pop())try {
119
+ if (!r.async && 1 === s) return s = 0, env.stack.push(r), Promise.resolve().then(next);
120
+ if (r.dispose) {
121
+ var result = r.dispose.call(r.value);
122
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
123
+ fail(e);
124
+ return next();
125
+ });
126
+ } else s |= 1;
127
+ } catch (e) {
128
+ fail(e);
129
+ }
130
+ if (1 === s) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
131
+ if (env.hasError) throw env.error;
132
+ }
133
+ return next();
134
+ })(env);
135
+ }
136
+ const pluginAreTheTypesWrong = (options = {})=>({
137
+ name: "plugin-arethetypeswrong",
138
+ setup (api) {
139
+ if (false === options.enable) return;
140
+ api.onAfterBuild({
141
+ handler: async ({ isFirstCompile, isWatch })=>{
142
+ const env = {
143
+ stack: [],
144
+ error: void 0,
145
+ hasError: false
146
+ };
147
+ try {
148
+ if (!isFirstCompile) return;
149
+ const { rootPath } = api.context;
150
+ const packageJson = JSON.parse(node_fs.readFileSync(node_path.join(rootPath, "package.json"), "utf-8"));
151
+ const packageName = packageJson.name;
152
+ const packageVersion = packageJson.version;
153
+ logger.start(`[arethetypeswrong] Checking ${packageName}@${packageVersion}...`);
154
+ logger.info("");
155
+ logger.debug(`[arethetypeswrong] Running npm pack from ${rootPath}`);
156
+ const { createTarball } = await import("./createTarball.js");
157
+ const tarball = _ts_add_disposable_resource(env, await createTarball(rootPath, packageJson), true);
158
+ logger.debug("[arethetypeswrong] npm pack success");
159
+ const { checkPackage, createPackageFromTarballData } = await import("./@arethetypeswrong/core.js");
160
+ const pkg = createPackageFromTarballData(node_fs.readFileSync(tarball.path));
161
+ const result = await checkPackage(pkg);
162
+ const { render } = await import("./render.js");
163
+ const message = render(result, options.areTheTypesWrongOptions ?? {});
164
+ const { getExitCode } = await import("./getExitCode.js");
165
+ const exitCode = getExitCode(result, options.areTheTypesWrongOptions);
166
+ const hasErrors = 0 !== exitCode;
167
+ if (hasErrors) {
168
+ logger.error(message);
169
+ if (!isWatch) throw new Error("arethetypeswrong failed!");
170
+ return;
171
+ }
172
+ logger.success(message);
173
+ } catch (e) {
174
+ env.error = e;
175
+ env.hasError = true;
176
+ } finally{
177
+ const result = src_ts_dispose_resources(env);
178
+ if (result) await result;
179
+ }
180
+ },
181
+ order: "post"
182
+ });
183
+ }
184
+ });
185
+ export { __webpack_require__temp as __webpack_require__, __webpack_require__, pluginAreTheTypesWrong };
package/dist/854.js ADDED
@@ -0,0 +1,156 @@
1
+ import { getResolutionKinds } from "./utils.js";
2
+ const problemKindInfo = {
3
+ NoResolution: {
4
+ emoji: "💀",
5
+ title: "Resolution failed",
6
+ shortDescription: "Resolution failed",
7
+ description: "Import failed to resolve to type declarations or JavaScript files.",
8
+ docsUrl: "https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/NoResolution.md"
9
+ },
10
+ UntypedResolution: {
11
+ emoji: "❌",
12
+ title: "Could not find types",
13
+ shortDescription: "No types",
14
+ description: "Import resolved to JavaScript files, but no type declarations were found.",
15
+ docsUrl: "https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/UntypedResolution.md"
16
+ },
17
+ FalseCJS: {
18
+ emoji: "🎭",
19
+ title: "Types are CJS, but implementation is ESM",
20
+ shortDescription: "Masquerading as CJS",
21
+ description: "Import resolved to a CommonJS type declaration file, but an ESM JavaScript file.",
22
+ docsUrl: "https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseCJS.md"
23
+ },
24
+ FalseESM: {
25
+ emoji: "👺",
26
+ title: "Types are ESM, but implementation is CJS",
27
+ shortDescription: "Masquerading as ESM",
28
+ description: "Import resolved to an ESM type declaration file, but a CommonJS JavaScript file.",
29
+ docsUrl: "https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseESM.md"
30
+ },
31
+ NamedExports: {
32
+ emoji: "🕵️",
33
+ title: "Named exports cannot be detected by Node.js",
34
+ shortDescription: "Named exports",
35
+ description: "TypeScript allows ESM named imports of the properties of this CommonJS module, but they will crash at runtime because they don’t exist or can’t be statically detected by Node.js in the JavaScript file.",
36
+ details: "the list of exports TypeScript can see but Node.js cannot",
37
+ docsUrl: "https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/NamedExports.md"
38
+ },
39
+ CJSResolvesToESM: {
40
+ emoji: "⚠️",
41
+ title: "Entrypoint is ESM-only",
42
+ shortDescription: "ESM (dynamic import only)",
43
+ description: "A `require` call resolved to an ESM JavaScript file, which is an error in Node and some bundlers. CommonJS consumers will need to use a dynamic import.",
44
+ docsUrl: "https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/CJSResolvesToESM.md"
45
+ },
46
+ FallbackCondition: {
47
+ emoji: "🐛",
48
+ title: "Resolved through fallback condition",
49
+ shortDescription: "Used fallback condition",
50
+ description: "Import resolved to types through a conditional package.json export, but only after failing to resolve through an earlier condition. This behavior is a [TypeScript bug](https://github.com/microsoft/TypeScript/issues/50762). It may misrepresent the runtime behavior of this import and should not be relied upon.",
51
+ docsUrl: "https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FallbackCondition.md"
52
+ },
53
+ CJSOnlyExportsDefault: {
54
+ emoji: "🤨",
55
+ title: "CJS module uses default export",
56
+ shortDescription: "CJS default export",
57
+ description: "CommonJS module simulates a default export with `exports.default` and `exports.__esModule`, but does not also set `module.exports` for compatibility with Node. Node, and [some bundlers under certain conditions](https://andrewbranch.github.io/interop-test/#synthesizing-default-exports-for-cjs-modules), do not respect the `__esModule` marker, so accessing the intended default export will require a `.default` property access on the default import.",
58
+ docsUrl: "https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/CJSOnlyExportsDefault.md"
59
+ },
60
+ FalseExportDefault: {
61
+ emoji: "❗️",
62
+ title: "Types incorrectly use default export",
63
+ shortDescription: "Incorrect default export",
64
+ description: "The resolved types use `export default` where the JavaScript file appears to use `module.exports =`. This will cause TypeScript under the `node16` module mode to think an extra `.default` property access is required, but that will likely fail at runtime. These types should use `export =` instead of `export default`.",
65
+ docsUrl: "https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseExportDefault.md"
66
+ },
67
+ MissingExportEquals: {
68
+ emoji: "❓",
69
+ title: "Types are missing an `export =`",
70
+ shortDescription: "Missing `export =`",
71
+ description: "The JavaScript appears to set both `module.exports` and `module.exports.default` for improved compatibility, but the types only reflect the latter (by using `export default`). This will cause TypeScript under the `node16` module mode to think an extra `.default` property access is required, which will work at runtime but is not necessary. These types should `export =` an object with a `default` property instead of using `export default`.",
72
+ docsUrl: "https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/MissingExportEquals.md"
73
+ },
74
+ UnexpectedModuleSyntax: {
75
+ emoji: "🚭",
76
+ title: "Syntax is incompatible with detected module kind",
77
+ shortDescription: "Unexpected module syntax",
78
+ description: "Syntax detected in the module is incompatible with the module kind according to the package.json or file extension. This is an error in Node and may cause problems in some bundlers.",
79
+ docsUrl: "https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/UnexpectedModuleSyntax.md"
80
+ },
81
+ InternalResolutionError: {
82
+ emoji: "🥴",
83
+ title: "Internal resolution error",
84
+ shortDescription: "Internal resolution error",
85
+ description: "Import found in a type declaration file failed to resolve. Either this indicates that runtime resolution errors will occur, or (more likely) the types misrepresent the contents of the JavaScript files.",
86
+ details: "the imports that failed to resolve",
87
+ docsUrl: "https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/InternalResolutionError.md"
88
+ }
89
+ };
90
+ Object.keys(problemKindInfo);
91
+ function filterProblems(...args) {
92
+ const [problems, analysis, filter] = 2 === args.length ? [
93
+ args[0].problems,
94
+ ...args
95
+ ] : args;
96
+ return problems.filter((p)=>{
97
+ if (filter.kind && !filter.kind.includes(p.kind)) return false;
98
+ if (filter.entrypoint && filter.resolutionKind) return problemAffectsEntrypointResolution(p, filter.entrypoint, filter.resolutionKind, analysis);
99
+ if (filter.entrypoint && filter.resolutionOption) return getResolutionKinds(filter.resolutionOption).every((resolutionKind)=>problemAffectsEntrypointResolution(p, filter.entrypoint, resolutionKind, analysis));
100
+ if (filter.entrypoint) return problemAffectsEntrypoint(p, filter.entrypoint, analysis);
101
+ if (filter.resolutionKind) return problemAffectsResolutionKind(p, filter.resolutionKind, analysis);
102
+ return true;
103
+ });
104
+ }
105
+ function problemAffectsResolutionKind(problem, resolutionKind, analysis) {
106
+ var _a;
107
+ const index = getProblemIndex(analysis, problem);
108
+ for (const entrypoint of Object.values(analysis.entrypoints))if (null == (_a = entrypoint.resolutions[resolutionKind].visibleProblems) ? void 0 : _a.includes(index)) return true;
109
+ return false;
110
+ }
111
+ function problemAffectsEntrypoint(problem, entrypoint, analysis) {
112
+ var _a;
113
+ const index = getProblemIndex(analysis, problem);
114
+ for (const resolution of Object.values(analysis.entrypoints[entrypoint].resolutions))if (null == (_a = resolution.visibleProblems) ? void 0 : _a.includes(index)) return true;
115
+ return false;
116
+ }
117
+ function problemAffectsEntrypointResolution(problem, entrypoint, resolutionKind, analysis) {
118
+ var _a, _b;
119
+ const index = getProblemIndex(analysis, problem);
120
+ return null != (_b = null == (_a = analysis.entrypoints[entrypoint].resolutions[resolutionKind].visibleProblems) ? void 0 : _a.includes(index)) ? _b : false;
121
+ }
122
+ function getProblemIndex(analysis, problem) {
123
+ let index = analysis.problems.indexOf(problem);
124
+ if (-1 === index) {
125
+ const serialized = JSON.stringify(problem);
126
+ index = analysis.problems.findIndex((p)=>JSON.stringify(p) === serialized);
127
+ if (-1 === index) throw new Error("Could not find problem in analysis");
128
+ }
129
+ return index;
130
+ }
131
+ const problemFlags = {
132
+ NoResolution: "no-resolution",
133
+ UntypedResolution: "untyped-resolution",
134
+ FalseCJS: "false-cjs",
135
+ FalseESM: "false-esm",
136
+ CJSResolvesToESM: "cjs-resolves-to-esm",
137
+ FallbackCondition: "fallback-condition",
138
+ CJSOnlyExportsDefault: "cjs-only-exports-default",
139
+ NamedExports: "named-exports",
140
+ FalseExportDefault: "false-export-default",
141
+ MissingExportEquals: "missing-export-equals",
142
+ UnexpectedModuleSyntax: "unexpected-module-syntax",
143
+ InternalResolutionError: "internal-resolution-error"
144
+ };
145
+ const resolutionKinds = {
146
+ node10: "node10",
147
+ "node16-cjs": "node16 (from CJS)",
148
+ "node16-esm": "node16 (from ESM)",
149
+ bundler: "bundler"
150
+ };
151
+ const moduleKinds = {
152
+ 1: "(CJS)",
153
+ 99: "(ESM)",
154
+ "": ""
155
+ };
156
+ export { filterProblems, moduleKinds, problemAffectsEntrypoint, problemAffectsResolutionKind, problemFlags, problemKindInfo, resolutionKinds };
@@ -1,8 +1,8 @@
1
- /*! For license information please see 727.js.LICENSE.txt */
2
- import { __webpack_require__ } from "./rslib-runtime.js";
1
+ /*! LICENSE: core.js.LICENSE.txt */
3
2
  import typescript from "typescript";
4
- import "./363.js";
5
- import { getResolutionOption, getResolutionKinds, visitResolutions, allBuildTools, resolvedThroughFallback } from "./520.js";
3
+ import { createRequire } from "module";
4
+ import { __webpack_require__ } from "../453.js";
5
+ import { getResolutionOption, getResolutionKinds, visitResolutions, allBuildTools, resolvedThroughFallback } from "../utils.js";
6
6
  __webpack_require__.add({
7
7
  "./node_modules/.pnpm/@andrewbranch+untar.js@1.0.3/node_modules/@andrewbranch/untar.js/lib/bytestream.js" (module) {
8
8
  const ByteStream = function(ab, opt_offset, opt_length) {
@@ -100,7 +100,7 @@ __webpack_require__.add({
100
100
  const remaining = 512 - bstream.ptr % 512;
101
101
  if (remaining > 0 && remaining < 512) bstream.readBytes(remaining);
102
102
  }
103
- module.exports.untar = function(arrayBuffer) {
103
+ module.exports.P = function(arrayBuffer) {
104
104
  const bstream = new ByteStream(arrayBuffer);
105
105
  const localFiles = [];
106
106
  while(0 != bstream.peekNumber(4)){
@@ -220,8 +220,7 @@ const cjsOnlyExportsDefault = defineCheck({
220
220
  }
221
221
  }
222
222
  });
223
- const external_module_ = __webpack_require__("module");
224
- var esm_require = (0, external_module_.createRequire)('/');
223
+ var esm_require = createRequire('/');
225
224
  try {
226
225
  esm_require('worker_threads').Worker;
227
226
  } catch (e) {}
@@ -682,7 +681,7 @@ function extractTarball(tarball) {
682
681
  var _a;
683
682
  let unzipped;
684
683
  new esm_Gunzip((chunk)=>unzipped = chunk).push(tarball, true);
685
- const data = (0, untar.untar)(unzipped);
684
+ const data = (0, untar.P)(unzipped);
686
685
  const prefix = data[0].filename.substring(0, data[0].filename.indexOf("/") + 1);
687
686
  const packageJsonText = null == (_a = data.find((f)=>f.filename === `${prefix}package.json`)) ? void 0 : _a.fileData;
688
687
  const packageJson = JSON.parse(new TextDecoder().decode(packageJsonText));