@rspack/core 0.6.5-canary-6d6fcd3-20240514084813 → 0.6.5-canary-2456d69-20240515093621

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 (146) hide show
  1. package/dist/Chunk.d.ts +1 -1
  2. package/dist/Chunk.js +1 -1
  3. package/dist/ChunkGroup.d.ts +1 -1
  4. package/dist/ChunkGroup.js +3 -3
  5. package/dist/Compilation.d.ts +46 -65
  6. package/dist/Compilation.js +128 -222
  7. package/dist/Compiler.d.ts +75 -44
  8. package/dist/Compiler.js +325 -278
  9. package/dist/ContextModuleFactory.d.ts +7 -3
  10. package/dist/ContextModuleFactory.js +2 -2
  11. package/dist/Entrypoint.d.ts +1 -1
  12. package/dist/Entrypoint.js +1 -1
  13. package/dist/ExecuteModulePlugin.js +1 -1
  14. package/dist/Module.d.ts +11 -0
  15. package/dist/Module.js +2 -2
  16. package/dist/MultiCompiler.d.ts +10 -25
  17. package/dist/MultiCompiler.js +3 -3
  18. package/dist/MultiStats.d.ts +1 -1
  19. package/dist/NormalModuleFactory.d.ts +1 -1
  20. package/dist/Stats.d.ts +2 -2
  21. package/dist/Watching.d.ts +0 -9
  22. package/dist/Watching.js +12 -2
  23. package/dist/builtin-loader/swc/index.d.ts +6 -6
  24. package/dist/builtin-loader/swc/index.js +3 -3
  25. package/dist/builtin-loader/swc/types.d.ts +2 -2
  26. package/dist/builtin-plugin/APIPlugin.d.ts +1 -1
  27. package/dist/builtin-plugin/ArrayPushCallbackChunkFormatPlugin.d.ts +1 -1
  28. package/dist/builtin-plugin/AssetModulesPlugin.d.ts +1 -1
  29. package/dist/builtin-plugin/AsyncWebAssemblyModulesPlugin.d.ts +1 -1
  30. package/dist/builtin-plugin/BannerPlugin.d.ts +2 -2
  31. package/dist/builtin-plugin/BannerPlugin.js +1 -1
  32. package/dist/builtin-plugin/BundlerInfoRspackPlugin.d.ts +1 -1
  33. package/dist/builtin-plugin/ChunkPrefetchPreloadPlugin.d.ts +1 -1
  34. package/dist/builtin-plugin/CommonJsChunkFormatPlugin.d.ts +1 -1
  35. package/dist/builtin-plugin/CopyRspackPlugin.d.ts +1 -1
  36. package/dist/builtin-plugin/CssModulesPlugin.d.ts +1 -1
  37. package/dist/builtin-plugin/DataUriPlugin.d.ts +1 -1
  38. package/dist/builtin-plugin/DefinePlugin.d.ts +1 -1
  39. package/dist/builtin-plugin/DeterministicChunkIdsPlugin.d.ts +1 -1
  40. package/dist/builtin-plugin/DeterministicModuleIdsPlugin.d.ts +1 -1
  41. package/dist/builtin-plugin/DynamicEntryPlugin.d.ts +1 -1
  42. package/dist/builtin-plugin/DynamicEntryPlugin.js +1 -1
  43. package/dist/builtin-plugin/ElectronTargetPlugin.d.ts +1 -1
  44. package/dist/builtin-plugin/EnableChunkLoadingPlugin.d.ts +1 -1
  45. package/dist/builtin-plugin/EnableLibraryPlugin.d.ts +1 -1
  46. package/dist/builtin-plugin/EnableWasmLoadingPlugin.d.ts +1 -1
  47. package/dist/builtin-plugin/EnsureChunkConditionsPlugin.d.ts +1 -1
  48. package/dist/builtin-plugin/EntryPlugin.d.ts +1 -1
  49. package/dist/builtin-plugin/EntryPlugin.js +1 -1
  50. package/dist/builtin-plugin/EvalDevToolModulePlugin.d.ts +1 -1
  51. package/dist/builtin-plugin/EvalSourceMapDevToolPlugin.d.ts +1 -1
  52. package/dist/builtin-plugin/ExternalsPlugin.d.ts +3 -3
  53. package/dist/builtin-plugin/FileUriPlugin.d.ts +1 -1
  54. package/dist/builtin-plugin/FlagDependencyExportsPlugin.d.ts +1 -1
  55. package/dist/builtin-plugin/FlagDependencyUsagePlugin.d.ts +1 -1
  56. package/dist/builtin-plugin/HtmlRspackPlugin.d.ts +2 -2
  57. package/dist/builtin-plugin/HtmlRspackPlugin.js +2 -2
  58. package/dist/builtin-plugin/HttpExternalsRspackPlugin.d.ts +1 -1
  59. package/dist/builtin-plugin/IgnorePlugin.d.ts +1 -1
  60. package/dist/builtin-plugin/InferAsyncModulesPlugin.d.ts +1 -1
  61. package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +1 -1
  62. package/dist/builtin-plugin/JsLoaderRspackPlugin.d.ts +1 -1
  63. package/dist/builtin-plugin/JsLoaderRspackPlugin.js +1 -1
  64. package/dist/builtin-plugin/JsonModulesPlugin.d.ts +1 -1
  65. package/dist/builtin-plugin/LimitChunkCountPlugin.d.ts +1 -1
  66. package/dist/builtin-plugin/MangleExportsPlugin.d.ts +1 -1
  67. package/dist/builtin-plugin/MergeDuplicateChunksPlugin.d.ts +1 -1
  68. package/dist/builtin-plugin/ModuleChunkFormatPlugin.d.ts +1 -1
  69. package/dist/builtin-plugin/ModuleConcatenationPlugin.d.ts +1 -1
  70. package/dist/builtin-plugin/NamedChunkIdsPlugin.d.ts +1 -1
  71. package/dist/builtin-plugin/NamedModuleIdsPlugin.d.ts +1 -1
  72. package/dist/builtin-plugin/NodeTargetPlugin.d.ts +1 -1
  73. package/dist/builtin-plugin/ProgressPlugin.d.ts +1 -1
  74. package/dist/builtin-plugin/ProvidePlugin.d.ts +1 -1
  75. package/dist/builtin-plugin/RealContentHashPlugin.d.ts +1 -1
  76. package/dist/builtin-plugin/RemoveEmptyChunksPlugin.d.ts +1 -1
  77. package/dist/builtin-plugin/RuntimeChunkPlugin.d.ts +1 -1
  78. package/dist/builtin-plugin/RuntimePlugin.d.ts +1 -1
  79. package/dist/builtin-plugin/SideEffectsFlagPlugin.d.ts +1 -1
  80. package/dist/builtin-plugin/SizeLimitsPlugin.d.ts +1 -1
  81. package/dist/builtin-plugin/SourceMapDevToolPlugin.d.ts +1 -1
  82. package/dist/builtin-plugin/SplitChunksPlugin.d.ts +2 -2
  83. package/dist/builtin-plugin/SplitChunksPlugin.js +4 -4
  84. package/dist/builtin-plugin/SwcCssMinimizerPlugin.d.ts +1 -1
  85. package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +1 -1
  86. package/dist/builtin-plugin/WarnCaseSensitiveModulesPlugin.d.ts +1 -1
  87. package/dist/builtin-plugin/WebWorkerTemplatePlugin.d.ts +1 -1
  88. package/dist/builtin-plugin/WorkerPlugin.d.ts +2 -2
  89. package/dist/builtin-plugin/base.d.ts +1 -1
  90. package/dist/builtin-plugin/css-extract/index.d.ts +5 -4
  91. package/dist/builtin-plugin/css-extract/loader.d.ts +1 -1
  92. package/dist/builtin-plugin/css-extract/loader.js +2 -2
  93. package/dist/builtin-plugin/index.d.ts +43 -43
  94. package/dist/builtin-plugin/index.js +43 -43
  95. package/dist/config/adapter.d.ts +2 -2
  96. package/dist/config/adapter.js +6 -5
  97. package/dist/config/adapterRuleUse.d.ts +2 -1
  98. package/dist/config/adapterRuleUse.js +2 -2
  99. package/dist/config/defaults.js +6 -4
  100. package/dist/config/index.d.ts +2 -2
  101. package/dist/config/index.js +2 -2
  102. package/dist/config/normalization.d.ts +1 -2
  103. package/dist/config/zod.d.ts +258 -184
  104. package/dist/config/zod.js +8 -28
  105. package/dist/container/ContainerPlugin.d.ts +1 -1
  106. package/dist/container/ContainerReferencePlugin.d.ts +1 -1
  107. package/dist/container/ContainerReferencePlugin.js +1 -1
  108. package/dist/container/ModuleFederationPlugin.js +1 -1
  109. package/dist/container/ModuleFederationPluginV1.d.ts +1 -1
  110. package/dist/container/ModuleFederationPluginV1.js +1 -1
  111. package/dist/container/ModuleFederationRuntimePlugin.d.ts +1 -1
  112. package/dist/exports.d.ts +34 -30
  113. package/dist/exports.js +21 -18
  114. package/dist/fileSystem.d.ts +12 -8
  115. package/dist/fileSystem.js +25 -48
  116. package/dist/index.d.ts +1 -1
  117. package/dist/index.js +1 -1
  118. package/dist/lite-tapable/index.d.ts +6 -0
  119. package/dist/lite-tapable/index.js +107 -1
  120. package/dist/loader-runner/index.js +13 -13
  121. package/dist/logging/Logger.d.ts +1 -1
  122. package/dist/logging/createConsoleLogger.js +0 -14
  123. package/dist/node/NodeEnvironmentPlugin.d.ts +1 -1
  124. package/dist/node/NodeEnvironmentPlugin.js +1 -1
  125. package/dist/node/nodeConsole.js +0 -4
  126. package/dist/rspack.d.ts +4 -13
  127. package/dist/rspack.js +8 -8
  128. package/dist/rspackOptionsApply.d.ts +1 -10
  129. package/dist/rspackOptionsApply.js +14 -5
  130. package/dist/sharing/ConsumeSharedPlugin.d.ts +1 -1
  131. package/dist/sharing/ConsumeSharedPlugin.js +1 -1
  132. package/dist/stats/DefaultStatsFactoryPlugin.js +2 -2
  133. package/dist/stats/StatsFactory.d.ts +2 -2
  134. package/dist/stats/StatsFactory.js +0 -9
  135. package/dist/stats/StatsPrinter.d.ts +1 -1
  136. package/dist/stats/statsFactoryUtils.d.ts +1 -1
  137. package/dist/util/comparators.d.ts +1 -1
  138. package/dist/util/fs.d.ts +64 -0
  139. package/dist/util/fs.js +122 -0
  140. package/dist/util/index.d.ts +2 -1
  141. package/dist/util/index.js +16 -11
  142. package/dist/util/source.d.ts +18 -0
  143. package/dist/util/source.js +66 -0
  144. package/package.json +4 -4
  145. package/dist/util/createSource.d.ts +0 -5
  146. package/dist/util/createSource.js +0 -65
package/dist/util/fs.js CHANGED
@@ -1,2 +1,124 @@
1
1
  "use strict";
2
+ /**
3
+ * The following code is modified based on
4
+ * https://github.com/webpack/webpack/blob/4b4ca3b/lib/util/fs.js
5
+ *
6
+ * MIT Licensed
7
+ * Author Tobias Koppers @sokra
8
+ * Copyright (c) JS Foundation and other contributors
9
+ * https://github.com/webpack/webpack/blob/main/LICENSE
10
+ */
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.mkdirp = exports.rmrf = void 0;
16
+ const assert_1 = __importDefault(require("assert"));
17
+ const path_1 = __importDefault(require("path"));
18
+ function rmrf(fs, p, callback) {
19
+ fs.stat(p, (err, stats) => {
20
+ if (err) {
21
+ if (err.code === "ENOENT") {
22
+ return callback();
23
+ }
24
+ return callback(err);
25
+ }
26
+ if (stats.isDirectory()) {
27
+ fs.readdir(p, (err, files) => {
28
+ if (err) {
29
+ return callback(err);
30
+ }
31
+ let count = files.length;
32
+ if (count === 0) {
33
+ fs.rmdir(p, callback);
34
+ }
35
+ else {
36
+ files.forEach(file => {
37
+ (0, assert_1.default)(typeof file === "string");
38
+ const fullPath = join(fs, p, file);
39
+ rmrf(fs, fullPath, err => {
40
+ if (err) {
41
+ return callback(err);
42
+ }
43
+ count--;
44
+ if (count === 0) {
45
+ fs.rmdir(p, callback);
46
+ }
47
+ });
48
+ });
49
+ }
50
+ });
51
+ }
52
+ else {
53
+ fs.unlink(p, callback);
54
+ }
55
+ });
56
+ }
57
+ exports.rmrf = rmrf;
58
+ const join = (fs, rootPath, filename) => {
59
+ if (fs && fs.join) {
60
+ return fs.join(rootPath, filename);
61
+ }
62
+ else if (path_1.default.posix.isAbsolute(rootPath)) {
63
+ return path_1.default.posix.join(rootPath, filename);
64
+ }
65
+ else if (path_1.default.win32.isAbsolute(rootPath)) {
66
+ return path_1.default.win32.join(rootPath, filename);
67
+ }
68
+ else {
69
+ throw new Error(`${rootPath} is neither a posix nor a windows path, and there is no 'join' method defined in the file system`);
70
+ }
71
+ };
72
+ const dirname = (fs, absPath) => {
73
+ if (fs && fs.dirname) {
74
+ return fs.dirname(absPath);
75
+ }
76
+ else if (path_1.default.posix.isAbsolute(absPath)) {
77
+ return path_1.default.posix.dirname(absPath);
78
+ }
79
+ else if (path_1.default.win32.isAbsolute(absPath)) {
80
+ return path_1.default.win32.dirname(absPath);
81
+ }
82
+ else {
83
+ throw new Error(`${absPath} is neither a posix nor a windows path, and there is no 'dirname' method defined in the file system`);
84
+ }
85
+ };
86
+ const mkdirp = (fs, p, callback) => {
87
+ fs.mkdir(p, err => {
88
+ if (err) {
89
+ if (err.code === "ENOENT") {
90
+ const dir = dirname(fs, p);
91
+ if (dir === p) {
92
+ callback(err);
93
+ return;
94
+ }
95
+ (0, exports.mkdirp)(fs, dir, err => {
96
+ if (err) {
97
+ callback(err);
98
+ return;
99
+ }
100
+ fs.mkdir(p, err => {
101
+ if (err) {
102
+ if (err.code === "EEXIST") {
103
+ callback();
104
+ return;
105
+ }
106
+ callback(err);
107
+ return;
108
+ }
109
+ callback();
110
+ });
111
+ });
112
+ return;
113
+ }
114
+ else if (err.code === "EEXIST") {
115
+ callback();
116
+ return;
117
+ }
118
+ callback(err);
119
+ return;
120
+ }
121
+ callback();
122
+ });
123
+ };
124
+ exports.mkdirp = mkdirp;
@@ -11,7 +11,7 @@ export declare const toObject: (input: string | Buffer | object) => object;
11
11
  export declare function serializeObject(map: string | object | undefined | null): Buffer | undefined;
12
12
  export declare function isPromiseLike(value: unknown): value is Promise<any>;
13
13
  export declare function isJsStatsError(err: any): err is JsStatsError;
14
- export declare function concatErrorMsgAndStack(err: Error | JsStatsError): string;
14
+ export declare function concatErrorMsgAndStack(err: Error | JsStatsError | string): string;
15
15
  export declare function indent(str: string, prefix: string): string;
16
16
  export declare function stringifyLoaderObject(o: LoaderObject): string;
17
17
  export declare function asArray<T>(item: T[]): T[];
@@ -19,3 +19,4 @@ export declare function asArray<T>(item: readonly T[]): readonly T[];
19
19
  export declare function asArray<T>(item: T): T[];
20
20
  export declare function toJsAssetInfo(info?: AssetInfo): JsAssetInfo;
21
21
  export declare const deprecatedWarn: (content: string, enable?: boolean) => void;
22
+ export declare const unsupported: (name: string, issue?: string) => never;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deprecatedWarn = exports.toJsAssetInfo = exports.asArray = exports.stringifyLoaderObject = exports.indent = exports.concatErrorMsgAndStack = exports.isJsStatsError = exports.isPromiseLike = exports.serializeObject = exports.toObject = exports.toBuffer = exports.isNil = exports.mapValues = void 0;
3
+ exports.unsupported = exports.deprecatedWarn = exports.toJsAssetInfo = exports.asArray = exports.stringifyLoaderObject = exports.indent = exports.concatErrorMsgAndStack = exports.isJsStatsError = exports.isPromiseLike = exports.serializeObject = exports.toObject = exports.toBuffer = exports.isNil = exports.mapValues = void 0;
4
4
  function mapValues(record, fn) {
5
5
  return Object.fromEntries(Object.entries(record).map(([key, value]) => [key, fn(value)]));
6
6
  }
@@ -60,16 +60,13 @@ function isJsStatsError(err) {
60
60
  }
61
61
  exports.isJsStatsError = isJsStatsError;
62
62
  function concatErrorMsgAndStack(err) {
63
- // deduplicate the error if message is already shown in the stack
64
- //@ts-ignore
65
- const stackStartPrefix = err.name ? `${err.name}: ` : "Error: ";
66
- return isJsStatsError(err)
67
- ? err.formatted
68
- : err.stack
69
- ? err.stack.startsWith(`${stackStartPrefix}${err.message}`)
70
- ? `${err.stack}`
71
- : `${err.message}\n${err.stack}`
72
- : `${err.message}`;
63
+ if (typeof err === "string") {
64
+ return err;
65
+ }
66
+ if ("stack" in err) {
67
+ return err.stack || err.message;
68
+ }
69
+ return err.message;
73
70
  }
74
71
  exports.concatErrorMsgAndStack = concatErrorMsgAndStack;
75
72
  function indent(str, prefix) {
@@ -116,3 +113,11 @@ const deprecatedWarn = (content, enable = getDeprecationStatus()) => {
116
113
  }
117
114
  };
118
115
  exports.deprecatedWarn = deprecatedWarn;
116
+ const unsupported = (name, issue) => {
117
+ let s = `${name} is not supported by rspack.`;
118
+ if (issue) {
119
+ s += ` Please refer to issue ${issue} for more information.`;
120
+ }
121
+ throw new Error(s);
122
+ };
123
+ exports.unsupported = unsupported;
@@ -0,0 +1,18 @@
1
+ /// <reference types="node" />
2
+ import type { JsCompatSource } from "@rspack/binding";
3
+ import { Source } from "webpack-sources";
4
+ declare class JsSource extends Source {
5
+ static __from_binding(source: JsCompatSource): Source;
6
+ static __to_binding(source: Source): {
7
+ source: Buffer;
8
+ isRaw: boolean;
9
+ isBuffer: boolean;
10
+ map?: undefined;
11
+ } | {
12
+ source: Buffer;
13
+ map: Buffer;
14
+ isRaw: boolean;
15
+ isBuffer: boolean;
16
+ };
17
+ }
18
+ export { JsSource };
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsSource = void 0;
4
+ const webpack_sources_1 = require("webpack-sources");
5
+ const index_1 = require("./index");
6
+ class JsSource extends webpack_sources_1.Source {
7
+ static __from_binding(source) {
8
+ if (source.isRaw) {
9
+ return new webpack_sources_1.RawSource(
10
+ // @ts-expect-error: webpack-sources can accept buffer as source, see: https://github.com/webpack/webpack-sources/blob/9f98066311d53a153fdc7c633422a1d086528027/lib/RawSource.js#L12
11
+ source.isBuffer ? source.source : source.source.toString("utf-8"));
12
+ }
13
+ if (!source.map) {
14
+ return new webpack_sources_1.RawSource(source.source.toString("utf-8"));
15
+ }
16
+ return new webpack_sources_1.CompatSource({
17
+ source() {
18
+ return source.source.toString("utf-8");
19
+ },
20
+ buffer() {
21
+ return source.source;
22
+ },
23
+ map(_) {
24
+ if (source.map) {
25
+ return JSON.parse(source.map.toString("utf-8"));
26
+ }
27
+ return null;
28
+ }
29
+ });
30
+ }
31
+ static __to_binding(source) {
32
+ var _a, _b, _c;
33
+ const sourceSource = source.source();
34
+ const isBuffer = Buffer.isBuffer(sourceSource);
35
+ if (source instanceof webpack_sources_1.RawSource) {
36
+ return {
37
+ source: source.buffer(),
38
+ isRaw: true,
39
+ isBuffer
40
+ };
41
+ }
42
+ const buffer = (_b = (_a = source.buffer) === null || _a === void 0 ? void 0 : _a.call(source)) !== null && _b !== void 0 ? _b : (isBuffer
43
+ ? sourceSource
44
+ : sourceSource instanceof ArrayBuffer
45
+ ? arrayBufferToBuffer(sourceSource)
46
+ : Buffer.from(sourceSource));
47
+ const map = JSON.stringify((_c = source.map) === null || _c === void 0 ? void 0 : _c.call(source, {
48
+ columns: true
49
+ }));
50
+ return {
51
+ source: buffer,
52
+ map: (0, index_1.isNil)(map) ? map : Buffer.from(map),
53
+ isRaw: false,
54
+ isBuffer
55
+ };
56
+ }
57
+ }
58
+ exports.JsSource = JsSource;
59
+ function arrayBufferToBuffer(ab) {
60
+ const buf = Buffer.alloc(ab.byteLength);
61
+ const view = new Uint8Array(ab);
62
+ for (let i = 0; i < buf.length; ++i) {
63
+ buf[i] = view[i];
64
+ }
65
+ return buf;
66
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/core",
3
- "version": "0.6.5-canary-6d6fcd3-20240514084813",
3
+ "version": "0.6.5-canary-2456d69-20240515093621",
4
4
  "webpackVersion": "5.75.0",
5
5
  "license": "MIT",
6
6
  "description": "A Fast Rust-based Web Bundler",
@@ -71,8 +71,8 @@
71
71
  "watchpack": "^2.4.0",
72
72
  "zod": "^3.21.4",
73
73
  "zod-validation-error": "1.3.1",
74
- "@rspack/core": "0.6.5-canary-6d6fcd3-20240514084813",
75
- "@rspack/plugin-minify": "^0.6.5-canary-6d6fcd3-20240514084813"
74
+ "@rspack/core": "0.6.5-canary-2456d69-20240515093621",
75
+ "@rspack/plugin-minify": "^0.6.5-canary-2456d69-20240515093621"
76
76
  },
77
77
  "dependencies": {
78
78
  "@module-federation/runtime-tools": "0.1.6",
@@ -80,7 +80,7 @@
80
80
  "enhanced-resolve": "5.12.0",
81
81
  "tapable": "2.2.1",
82
82
  "webpack-sources": "3.2.3",
83
- "@rspack/binding": "0.6.5-canary-6d6fcd3-20240514084813"
83
+ "@rspack/binding": "0.6.5-canary-2456d69-20240515093621"
84
84
  },
85
85
  "peerDependencies": {
86
86
  "@swc/helpers": ">=0.5.1"
@@ -1,5 +0,0 @@
1
- import type { JsCompatSource } from "@rspack/binding";
2
- import { Source } from "webpack-sources";
3
- declare function createSourceFromRaw(source: JsCompatSource): Source;
4
- declare function createRawFromSource(source: Source): JsCompatSource;
5
- export { createSourceFromRaw, createRawFromSource };
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRawFromSource = exports.createSourceFromRaw = void 0;
4
- const webpack_sources_1 = require("webpack-sources");
5
- const index_1 = require("./index");
6
- function createSourceFromRaw(source) {
7
- if (source.isRaw) {
8
- return new webpack_sources_1.RawSource(
9
- // @ts-expect-error: webpack-sources can accept buffer as source, see: https://github.com/webpack/webpack-sources/blob/9f98066311d53a153fdc7c633422a1d086528027/lib/RawSource.js#L12
10
- source.isBuffer ? source.source : source.source.toString("utf-8"));
11
- }
12
- if (!source.map) {
13
- return new webpack_sources_1.RawSource(source.source.toString("utf-8"));
14
- }
15
- return new webpack_sources_1.CompatSource({
16
- source() {
17
- return source.source.toString("utf-8");
18
- },
19
- buffer() {
20
- return source.source;
21
- },
22
- map(_) {
23
- if (source.map) {
24
- return JSON.parse(source.map.toString("utf-8"));
25
- }
26
- return null;
27
- }
28
- });
29
- }
30
- exports.createSourceFromRaw = createSourceFromRaw;
31
- function createRawFromSource(source) {
32
- var _a, _b, _c;
33
- const sourceSource = source.source();
34
- const isBuffer = Buffer.isBuffer(sourceSource);
35
- if (source instanceof webpack_sources_1.RawSource) {
36
- return {
37
- source: source.buffer(),
38
- isRaw: true,
39
- isBuffer
40
- };
41
- }
42
- const buffer = (_b = (_a = source.buffer) === null || _a === void 0 ? void 0 : _a.call(source)) !== null && _b !== void 0 ? _b : (isBuffer
43
- ? sourceSource
44
- : sourceSource instanceof ArrayBuffer
45
- ? arrayBufferToBuffer(sourceSource)
46
- : Buffer.from(sourceSource));
47
- const map = JSON.stringify((_c = source.map) === null || _c === void 0 ? void 0 : _c.call(source, {
48
- columns: true
49
- }));
50
- return {
51
- source: buffer,
52
- map: (0, index_1.isNil)(map) ? map : Buffer.from(map),
53
- isRaw: false,
54
- isBuffer
55
- };
56
- }
57
- exports.createRawFromSource = createRawFromSource;
58
- function arrayBufferToBuffer(ab) {
59
- const buf = Buffer.alloc(ab.byteLength);
60
- const view = new Uint8Array(ab);
61
- for (let i = 0; i < buf.length; ++i) {
62
- buf[i] = view[i];
63
- }
64
- return buf;
65
- }