@ohos-ports/rspack-core 2.2.9-beta.0 → 2.3.4-beta.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.
Files changed (68) hide show
  1. package/README.md +7 -7
  2. package/compiled/http-proxy-middleware/index.d.ts +12 -10
  3. package/compiled/http-proxy-middleware/package.json +1 -1
  4. package/compiled/tinypool/dist/index.js +5 -3
  5. package/compiled/watchpack/index.js +459 -60
  6. package/compiled/watchpack/package.json +1 -1
  7. package/compiled/watchpack/types/DirectoryWatcher.d.ts +24 -0
  8. package/compiled/watchpack/types/index.d.ts +1 -1
  9. package/compiled/watchpack/types/watchEventSource.d.ts +9 -0
  10. package/compiled/webpack-sources/index.d.ts +2 -0
  11. package/compiled/webpack-sources/index.js +207 -94
  12. package/compiled/webpack-sources/package.json +1 -1
  13. package/compiled/webpack-sources/types/RawSource.d.ts +0 -10
  14. package/compiled/webpack-sources/types/helpers/sourceMap.d.ts +47 -0
  15. package/compiled/webpack-sources/types/index.d.ts +1 -0
  16. package/dist/BuildInfo.d.ts +7 -0
  17. package/dist/Compilation.d.ts +3 -1
  18. package/dist/Compiler.d.ts +5 -6
  19. package/dist/ConcatenatedModule.d.ts +5 -1
  20. package/dist/ContextModule.d.ts +3 -1
  21. package/dist/ExternalModule.d.ts +7 -6
  22. package/dist/FileSystemInfo.d.ts +1 -0
  23. package/dist/Module.d.ts +12 -8
  24. package/dist/ModuleGraphConnection.d.ts +9 -3
  25. package/dist/NativeWatchFileSystem.d.ts +19 -7
  26. package/dist/NormalModule.d.ts +14 -6
  27. package/dist/RuntimeGlobals.d.ts +2 -1
  28. package/dist/RuntimeTemplate.d.ts +2 -0
  29. package/dist/Stats.d.ts +1 -1
  30. package/dist/builtin-loader/lightningcss/index.d.ts +5 -1
  31. package/dist/builtin-plugin/CompactHashedChunkIdsPlugin.d.ts +1 -0
  32. package/dist/builtin-plugin/CompactHashedModuleIdsPlugin.d.ts +1 -0
  33. package/dist/builtin-plugin/DeterministicChunkIdsPlugin.d.ts +5 -0
  34. package/dist/builtin-plugin/EvalSourceMapDevToolPlugin.d.ts +3 -2
  35. package/dist/builtin-plugin/ImportedByDeferModulesPlugin.d.ts +9 -0
  36. package/dist/builtin-plugin/SubresourceIntegrityPlugin.d.ts +1 -0
  37. package/dist/builtin-plugin/index.d.ts +1 -0
  38. package/dist/builtin-plugin/lazy-compilation/lazyCompilation.d.ts +2 -2
  39. package/dist/config/adapterRuleUse.d.ts +1 -0
  40. package/dist/config/normalization.d.ts +2 -2
  41. package/dist/config/target.d.ts +6 -0
  42. package/dist/config/types.d.ts +69 -36
  43. package/dist/cssExtractHmr.js +1 -1
  44. package/dist/cssExtractLoader.js +1 -1
  45. package/dist/exports.d.ts +5 -4
  46. package/dist/index.js +1577 -1151
  47. package/dist/loader-runner/codeFilter.d.ts +9 -0
  48. package/dist/loader-runner/dependencies.d.ts +1 -1
  49. package/dist/loader-runner/index.d.ts +2 -1
  50. package/dist/loader-runner/service.d.ts +0 -4
  51. package/dist/loader-runner/worker.d.ts +4 -1
  52. package/dist/node/NodeWatchFileSystem.d.ts +7 -4
  53. package/dist/sharing/IndependentSharedPlugin.d.ts +1 -2
  54. package/dist/sharing/utils.d.ts +1 -1
  55. package/dist/sources.d.ts +3 -0
  56. package/dist/stats/statsFactoryUtils.d.ts +7 -0
  57. package/dist/util/bindingHelpers.d.ts +2 -0
  58. package/dist/util/createModule.d.ts +3 -0
  59. package/dist/util/fs.d.ts +13 -7
  60. package/dist/util/resolveLayerExternals.d.ts +1 -0
  61. package/dist/util/source.d.ts +12 -3
  62. package/dist/util/symbols.d.ts +10 -0
  63. package/dist/util/watchTimeInfo.d.ts +5 -1
  64. package/dist/worker.js +327 -326
  65. package/hot/lazy-compilation-node.js +1 -1
  66. package/hot/lazy-compilation-web.js +1 -1
  67. package/package.json +4 -4
  68. package/dist/loader-runner/cache.d.ts +0 -27
package/dist/worker.js CHANGED
@@ -22,7 +22,7 @@ makeNamespaceObject(swc_namespaceObject), definePropertyGetters(swc_namespaceObj
22
22
  transform: ()=>transform,
23
23
  transformSync: ()=>transformSync
24
24
  });
25
- let binding_namespaceObject = __rspack_createRequire_require(process.env.RSPACK_BINDING || "@rspack/binding");
25
+ let binding_namespaceObject = __rspack_createRequire_require(process.env.RSPACK_BINDING || "@ohos-ports/rspack-binding");
26
26
  var binding_default = compatGetDefaultExport(binding_namespaceObject);
27
27
  async function minify(source, options) {
28
28
  let _options = JSON.stringify(options || {});
@@ -40,15 +40,7 @@ function transformSync(source, options) {
40
40
  let _options = JSON.stringify(options || {});
41
41
  return binding_default().transformSync(source, _options);
42
42
  }
43
- let decoder = new TextDecoder(), toObject = (input)=>{
44
- let s;
45
- if (Buffer.isBuffer(input)) s = input.toString('utf8');
46
- else if (input instanceof Uint8Array) s = decoder.decode(input);
47
- else if (input && 'object' == typeof input) return input;
48
- else if ('string' == typeof input) s = input;
49
- else throw Error('Buffer or string or object expected');
50
- return JSON.parse(s);
51
- }, DYNAMIC_INFO = Symbol('cleverMerge dynamic info'), mergeCache = new WeakMap(), DELETE = Symbol('DELETE'), cachedCleverMerge = (first, second)=>{
43
+ let DYNAMIC_INFO = Symbol('cleverMerge dynamic info'), mergeCache = new WeakMap(), DELETE = Symbol('DELETE'), cachedCleverMerge = (first, second)=>{
52
44
  if (void 0 === second) return first;
53
45
  if (void 0 === first || 'object' != typeof second || null === second) return second;
54
46
  if ('object' != typeof first || null === first) return first;
@@ -96,7 +88,7 @@ let decoder = new TextDecoder(), toObject = (input)=>{
96
88
  static: info,
97
89
  dynamic: dynamicInfo
98
90
  };
99
- }, cleverMerge_serializeObject = (info, dynamicInfo)=>{
91
+ }, serializeObject = (info, dynamicInfo)=>{
100
92
  let obj = {};
101
93
  for (let entry of info.values())if (void 0 !== entry.byProperty) {
102
94
  let byObj = obj[entry.byProperty] = obj[entry.byProperty] || {};
@@ -122,7 +114,7 @@ let decoder = new TextDecoder(), toObject = (input)=>{
122
114
  return newFn[DYNAMIC_INFO] = [
123
115
  fn,
124
116
  secondObj
125
- ], cleverMerge_serializeObject(firstObject.static, {
117
+ ], serializeObject(firstObject.static, {
126
118
  byProperty,
127
119
  fn: newFn
128
120
  });
@@ -133,7 +125,7 @@ let decoder = new TextDecoder(), toObject = (input)=>{
133
125
  resultInfo.set(key, entry);
134
126
  }
135
127
  for (let [key, secondEntry] of secondInfo)firstInfo.has(key) || resultInfo.set(key, secondEntry);
136
- return cleverMerge_serializeObject(resultInfo, secondDynamicInfo);
128
+ return serializeObject(resultInfo, secondDynamicInfo);
137
129
  }, mergeEntries = (firstEntry, secondEntry, internalCaching)=>{
138
130
  switch(getValueType(secondEntry.base)){
139
131
  case 1:
@@ -510,7 +502,9 @@ makeCacheable(function(str) {
510
502
  let memoize = (fn)=>{
511
503
  let result, cache = !1, callback = fn;
512
504
  return ()=>(cache || (result = callback(), cache = !0, callback = void 0), result);
513
- }, LoaderLoadingError = class extends Error {
505
+ }, decoder = new TextDecoder('utf-8', {
506
+ fatal: !0
507
+ }), LoaderLoadingError = class extends Error {
514
508
  constructor(message){
515
509
  super(message), this.name = 'LoaderRunnerError', Error.captureStackTrace(this, this.constructor);
516
510
  }
@@ -593,6 +587,9 @@ function deserializeError(error) {
593
587
  return Object.assign(deserializedError, properties), shouldDeserializeAsAggregate || void 0 === errors || (deserializedError.errors = errors), deserializedError;
594
588
  }
595
589
  let utils_decoder = new TextDecoder();
590
+ function LOADER_EXECUTION(fn, context, args) {
591
+ return fn.apply(context, args);
592
+ }
596
593
  promisify(loadLoader);
597
594
  let utils_runSyncOrAsync = promisify(function(fn, context, args, callback) {
598
595
  let isSync = !0, isDone = !1, isError = !1, reportedError = !1;
@@ -617,7 +614,7 @@ let utils_runSyncOrAsync = promisify(function(fn, context, args, callback) {
617
614
  };
618
615
  context.callback = innerCallback;
619
616
  try {
620
- let result = fn.apply(context, args);
617
+ let result = LOADER_EXECUTION(fn, context, args);
621
618
  if (isSync) {
622
619
  if (isDone = !0, void 0 === result) return void callback(null, []);
623
620
  if (result && 'object' == typeof result && 'function' == typeof result.then) return void result.then((r)=>{
@@ -635,316 +632,7 @@ let utils_runSyncOrAsync = promisify(function(fn, context, args, callback) {
635
632
  if (isDone) return void (e instanceof Error ? console.error(e.stack) : console.error(e));
636
633
  isDone = !0, reportedError = !0, callback(e, []);
637
634
  }
638
- }), loadLoaderAsync = promisify(loadLoader);
639
- async function loaderImpl({ args, loaderContext, loaderState }, sendRequest, waitForPendingRequest) {
640
- let resourcePath = loaderContext.resourcePath, contextDirectory = resourcePath ? function(path) {
641
- if ('/' === path) return '/';
642
- let i = path.lastIndexOf('/'), j = path.lastIndexOf('\\'), i2 = path.indexOf('/'), j2 = path.indexOf('\\'), idx = i > j ? i : j, idx2 = i > j ? i2 : j2;
643
- return idx < 0 ? path : idx === idx2 ? path.slice(0, idx + 1) : path.slice(0, idx);
644
- }(resourcePath) : null, pendingDependencyRequest = [];
645
- loaderContext.parallel = !0, loaderContext.dependency = loaderContext.addDependency = function(file) {
646
- pendingDependencyRequest.push(sendRequest("AddDependency", file));
647
- }, loaderContext.addContextDependency = function(context) {
648
- pendingDependencyRequest.push(sendRequest("AddContextDependency", context));
649
- }, loaderContext.addMissingDependency = function(missing) {
650
- pendingDependencyRequest.push(sendRequest("AddMissingDependency", missing));
651
- }, loaderContext.addBuildDependency = function(file) {
652
- pendingDependencyRequest.push(sendRequest("AddBuildDependency", file));
653
- }, loaderContext.getDependencies = function() {
654
- return waitForPendingRequest(pendingDependencyRequest), sendRequest("GetDependencies").wait();
655
- }, loaderContext.getContextDependencies = function() {
656
- return waitForPendingRequest(pendingDependencyRequest), sendRequest("GetContextDependencies").wait();
657
- }, loaderContext.getMissingDependencies = function() {
658
- return waitForPendingRequest(pendingDependencyRequest), sendRequest("GetMissingDependencies").wait();
659
- }, loaderContext.clearDependencies = function() {
660
- pendingDependencyRequest.push(sendRequest("ClearDependencies"));
661
- };
662
- let beginDependencyChanges = ()=>sendRequest("BeginDependencyChanges"), mergeDependencyChanges = async ()=>{
663
- pendingDependencyRequest.length > 0 && (waitForPendingRequest(pendingDependencyRequest), pendingDependencyRequest.length = 0), await sendRequest("MergeDependencyChanges");
664
- };
665
- loaderContext.resolve = function(context, request, callback) {
666
- sendRequest("Resolve", context, request).then(([result, resolveRequest])=>{
667
- callback(null, result, resolveRequest);
668
- }, (err)=>{
669
- callback(err);
670
- });
671
- }, loaderContext.getResolve = function(options) {
672
- return function(context, request, callback) {
673
- if (!callback) return new Promise((resolve, reject)=>{
674
- sendRequest("GetResolve", options, context, request).then(([result])=>{
675
- resolve(result);
676
- }, (err)=>{
677
- reject(err);
678
- });
679
- });
680
- sendRequest("GetResolve", options, context, request).then(([result, resolveRequest])=>{
681
- callback(null, result, resolveRequest);
682
- }, (err)=>{
683
- callback(err);
684
- });
685
- };
686
- }, loaderContext.getLogger = function(name) {
687
- return {
688
- error (...args) {
689
- sendRequest("GetLogger", 'error', name, args);
690
- },
691
- warn (...args) {
692
- sendRequest("GetLogger", 'warn', name, args);
693
- },
694
- info (...args) {
695
- sendRequest("GetLogger", 'info', name, args);
696
- },
697
- log (...args) {
698
- sendRequest("GetLogger", 'log', name, args);
699
- },
700
- debug (...args) {
701
- sendRequest("GetLogger", 'debug', name, args);
702
- },
703
- assert (assertion, ...args) {
704
- assertion || sendRequest("GetLogger", 'error', name, args);
705
- },
706
- trace () {
707
- sendRequest("GetLogger", 'trace', name, [
708
- 'Trace'
709
- ]);
710
- },
711
- clear () {
712
- sendRequest("GetLogger", 'clear', name, []);
713
- },
714
- status (...args) {
715
- sendRequest("GetLogger", 'status', name, args);
716
- },
717
- group (...args) {
718
- sendRequest("GetLogger", 'group', name, args);
719
- },
720
- groupCollapsed (...args) {
721
- sendRequest("GetLogger", 'groupCollapsed', name, args);
722
- },
723
- groupEnd (...args) {
724
- sendRequest("GetLogger", 'groupEnd', name, args);
725
- },
726
- profile (label) {
727
- sendRequest("GetLogger", 'profile', name, [
728
- label
729
- ]);
730
- },
731
- profileEnd (label) {
732
- sendRequest("GetLogger", 'profileEnd', name, [
733
- label
734
- ]);
735
- },
736
- time (label) {
737
- sendRequest("GetLogger", 'time', name, [
738
- label
739
- ]);
740
- },
741
- timeEnd (label) {
742
- sendRequest("GetLogger", 'timeEnd', name, [
743
- label
744
- ]);
745
- },
746
- timeLog (label, ...args) {
747
- sendRequest("GetLogger", 'timeLog', name, [
748
- label,
749
- ...args
750
- ]);
751
- },
752
- timeAggregate (label) {
753
- sendRequest("GetLogger", 'timeAggregate', name, [
754
- label
755
- ]);
756
- },
757
- timeAggregateEnd (label) {
758
- sendRequest("GetLogger", 'timeAggregateEnd', name, [
759
- label
760
- ]);
761
- }
762
- };
763
- }, loaderContext.emitError = function(err) {
764
- sendRequest("EmitError", serializeError(err));
765
- }, loaderContext.emitWarning = function(warning) {
766
- sendRequest("EmitWarning", serializeError(warning));
767
- }, loaderContext.emitFile = function(name, content, sourceMap, assetInfo) {
768
- sendRequest("EmitFile", name, content, sourceMap, assetInfo);
769
- }, loaderContext.experiments = {
770
- emitDiagnostic (diagnostic) {
771
- sendRequest("EmitDiagnostic", diagnostic);
772
- }
773
- };
774
- let getAbsolutify = memoize(()=>absolutify.bindCache({})), getAbsolutifyInContext = memoize(()=>absolutify.bindContextCache(contextDirectory, {})), getContextify = memoize(()=>contextify.bindCache({})), getContextifyInContext = memoize(()=>contextify.bindContextCache(contextDirectory, {}));
775
- loaderContext.utils = {
776
- absolutify: (context, request)=>context === contextDirectory ? getAbsolutifyInContext()(request) : getAbsolutify()(context, request),
777
- contextify: (context, request)=>context === contextDirectory ? getContextifyInContext()(request) : getContextify()(context, request),
778
- createHash: (type)=>createHash_createHash(type || loaderContext._compilation.outputOptions.hashFunction)
779
- }, loaderContext._compiler = {
780
- ...loaderContext._compiler,
781
- rspack: {
782
- experiments: {
783
- swc: swc_namespaceObject
784
- }
785
- },
786
- webpack: {
787
- util: {
788
- createHash: createHash_createHash,
789
- cleverMerge: cleverMerge
790
- }
791
- }
792
- }, loaderContext._compilation = {
793
- ...loaderContext._compilation,
794
- getPath: (filename, data = {})=>(data.hash || (data = {
795
- hash: loaderContext._compilation.hash ?? void 0,
796
- ...data
797
- }), sendRequest("CompilationGetPath", 'function' == typeof filename ? filename(data) : filename, data).wait()),
798
- getPathWithInfo (filename, data = {}) {
799
- data.hash || (data = {
800
- hash: loaderContext._compilation.hash ?? void 0,
801
- ...data
802
- });
803
- let info = {}, result = sendRequest("CompilationGetPathWithInfo", 'function' == typeof filename ? filename(data, info) : filename, data, info).wait();
804
- return Object.assign(info, result.info), {
805
- path: result.path,
806
- info
807
- };
808
- },
809
- getAssetPath: (filename, data = {})=>sendRequest("CompilationGetAssetPath", 'function' == typeof filename ? filename(data) : filename, data).wait(),
810
- getAssetPathWithInfo (filename, data = {}) {
811
- let info = {}, result = sendRequest("CompilationGetAssetPathWithInfo", 'function' == typeof filename ? filename(data, info) : filename, data, info).wait();
812
- return Object.assign(info, result.info), {
813
- path: result.path,
814
- info
815
- };
816
- }
817
- };
818
- let _module = loaderContext._module, buildInfo = {
819
- ..._module.buildInfo ?? {}
820
- };
821
- loaderContext._module = {
822
- type: _module.type,
823
- identifier: ()=>_module.identifier,
824
- matchResource: _module.matchResource,
825
- request: _module.request,
826
- userRequest: _module.userRequest,
827
- rawRequest: _module.rawRequest,
828
- buildInfo
829
- }, loaderContext.importModule = function(request, options, callback) {
830
- if (!callback) return new Promise((resolve, reject)=>{
831
- sendRequest("ImportModule", request, options).then((result)=>{
832
- resolve(result);
833
- }, (err)=>{
834
- reject(err);
835
- });
836
- });
837
- sendRequest("ImportModule", request, options).then((result)=>{
838
- callback(null, result);
839
- }, (err)=>{
840
- callback(err);
841
- });
842
- }, loaderContext.fs = node_fs, Object.defineProperty(loaderContext, 'request', {
843
- enumerable: !0,
844
- get: ()=>loaderContext.loaders.map((o)=>o.request).concat(loaderContext.resource || '').join('!')
845
- }), Object.defineProperty(loaderContext, 'remainingRequest', {
846
- enumerable: !0,
847
- get: ()=>loaderContext.loaderIndex >= loaderContext.loaders.length - 1 && !loaderContext.resource ? '' : loaderContext.loaders.slice(loaderContext.loaderIndex + 1).map((o)=>o.request).concat(loaderContext.resource || '').join('!')
848
- }), Object.defineProperty(loaderContext, 'currentRequest', {
849
- enumerable: !0,
850
- get: ()=>loaderContext.loaders.slice(loaderContext.loaderIndex).map((o)=>o.request).concat(loaderContext.resource || '').join('!')
851
- }), Object.defineProperty(loaderContext, 'previousRequest', {
852
- enumerable: !0,
853
- get: ()=>loaderContext.loaders.slice(0, loaderContext.loaderIndex).map((o)=>o.request).join('!')
854
- }), Object.defineProperty(loaderContext, 'query', {
855
- enumerable: !0,
856
- get: ()=>{
857
- let entry = loaderContext.loaders[loaderContext.loaderIndex];
858
- return entry.options && 'object' == typeof entry.options ? entry.options : entry.query;
859
- }
860
- }), loaderContext.getOptions = function() {
861
- let loader = function(loaderContext, index = loaderContext.loaderIndex) {
862
- return loaderContext.loaders?.length && index < loaderContext.loaders.length && index >= 0 && loaderContext.loaders[index] ? loaderContext.loaders[index] : null;
863
- }(loaderContext), options = loader?.options;
864
- if ('string' == typeof options) if (options.startsWith('{') && options.endsWith('}')) try {
865
- options = JSON.parse(options);
866
- } catch (e) {
867
- throw Error(`JSON parsing failed for loader's string options: ${e.message}`);
868
- }
869
- else options = node_querystring.parse(options);
870
- return null == options && (options = {}), options;
871
- }, loaderContext.cacheable = function(flag) {
872
- !1 === flag && sendRequest("SetCacheable", !1);
873
- }, Object.defineProperty(loaderContext, 'data', {
874
- enumerable: !0,
875
- get: ()=>loaderContext.loaders[loaderContext.loaderIndex].loaderItem.data,
876
- set: (value)=>{
877
- loaderContext.loaders[loaderContext.loaderIndex].loaderItem.data = value;
878
- }
879
- });
880
- let shouldYieldToMainThread = (currentLoaderObject)=>!!(!currentLoaderObject?.parallel || currentLoaderObject?.request.startsWith('builtin:'));
881
- switch(loaderState){
882
- case binding_namespaceObject.JsLoaderState.Pitching:
883
- for(; loaderContext.loaderIndex < loaderContext.loaders.length;){
884
- let currentLoaderObject = loaderContext.loaders[loaderContext.loaderIndex];
885
- if (shouldYieldToMainThread(currentLoaderObject)) break;
886
- if (currentLoaderObject.pitchExecuted) {
887
- loaderContext.loaderIndex += 1;
888
- continue;
889
- }
890
- await loadLoaderAsync(currentLoaderObject, loaderContext._compiler);
891
- let fn = currentLoaderObject.pitch;
892
- if ((currentLoaderObject.pitchExecuted = !0, fn) && (args = await utils_runSyncOrAsync(fn, loaderContext, [
893
- loaderContext.remainingRequest,
894
- loaderContext.previousRequest,
895
- currentLoaderObject.loaderItem.data
896
- ]) || []).some((value)=>void 0 !== value)) break;
897
- }
898
- break;
899
- case binding_namespaceObject.JsLoaderState.Normal:
900
- for(; loaderContext.loaderIndex >= 0;){
901
- let cacheResult, currentLoaderObject = loaderContext.loaders[loaderContext.loaderIndex];
902
- if (shouldYieldToMainThread(currentLoaderObject)) break;
903
- if (currentLoaderObject.normalExecuted) {
904
- loaderContext.loaderIndex--;
905
- continue;
906
- }
907
- let trackDependencies = currentLoaderObject.loaderItem.cache;
908
- trackDependencies && await beginDependencyChanges();
909
- try {
910
- if (currentLoaderObject.loaderItem.cache) {
911
- waitForPendingRequest(pendingDependencyRequest);
912
- let result = await sendRequest("LoaderCacheGet", loaderContext.loaderIndex, args[0], args[2]);
913
- if (cacheResult = result, 'hit' === result.type) {
914
- let { entry } = result;
915
- currentLoaderObject.normalExecuted = !0, args = [
916
- 'string' == typeof entry.content ? entry.content : entry.content && Buffer.from(entry.content),
917
- entry.sourceMap ? toObject(Buffer.from(entry.sourceMap)) : void 0,
918
- void 0
919
- ];
920
- continue;
921
- }
922
- }
923
- await loadLoaderAsync(currentLoaderObject, loaderContext._compiler);
924
- let fn = currentLoaderObject.normal;
925
- if (currentLoaderObject.normalExecuted = !0, !fn) continue;
926
- !function(args, raw) {
927
- if (!raw && args[0] instanceof Uint8Array) {
928
- var buf;
929
- let isShared, str;
930
- args[0] = (isShared = (buf = args[0]).buffer instanceof SharedArrayBuffer || buf.buffer.constructor?.name === 'SharedArrayBuffer', str = utils_decoder.decode(isShared ? Buffer.from(buf) : buf), 0xfeff === str.charCodeAt(0) ? str.slice(1) : str);
931
- } else raw && 'string' == typeof args[0] && (args[0] = Buffer.from(args[0], 'utf-8'));
932
- raw && args[0] instanceof Uint8Array && !Buffer.isBuffer(args[0]) && (args[0] = Buffer.from(args[0].buffer, args[0].byteOffset, args[0].byteLength));
933
- }(args, !!currentLoaderObject.raw), args = await utils_runSyncOrAsync(fn, loaderContext, args) || [], cacheResult?.type === 'miss' && (waitForPendingRequest(pendingDependencyRequest), await sendRequest("LoaderCacheStore", loaderContext.loaderIndex, args[0], function(map) {
934
- if (null != map) return 'string' == typeof map ? map ? Buffer.from(map) : void 0 : Buffer.from(JSON.stringify(map));
935
- }(args[1]), args[2]));
936
- } finally{
937
- trackDependencies && await mergeDependencyChanges();
938
- }
939
- }
940
- }
941
- return sendRequest("UpdateLoaderObjects", loaderContext.loaders.map((item)=>({
942
- data: item.loaderItem.data,
943
- normalExecuted: item.normalExecuted,
944
- pitchExecuted: item.pitchExecuted
945
- }))), sendRequest("UpdateBuildInfo", buildInfo), args;
946
- }
947
- let nextId = 0, responseCallbacks = {};
635
+ }), loadLoaderAsync = promisify(loadLoader), nextId = 0, responseCallbacks = {};
948
636
  function handleIncomingResponses(workerMessage) {
949
637
  if (isWorkerResponseMessage(workerMessage)) {
950
638
  let { id, data } = workerMessage, callback = responseCallbacks[id];
@@ -992,7 +680,320 @@ export default function(workerOptions) {
992
680
  }), sendRequest), waitFor = (requests)=>sendRequest1.sync("WaitForPendingRequest", (Array.isArray(requests) ? requests : [
993
681
  requests
994
682
  ]).map((request)=>request.id));
995
- loaderImpl(workerOptions, sendRequest1, waitFor).then((data)=>{
683
+ (async function({ args, loaderContext, loaderState }, sendRequest, waitForPendingRequest) {
684
+ let resourcePath = loaderContext.resourcePath, contextDirectory = resourcePath ? function(path) {
685
+ if ('/' === path) return '/';
686
+ let i = path.lastIndexOf('/'), j = path.lastIndexOf('\\'), i2 = path.indexOf('/'), j2 = path.indexOf('\\'), idx = i > j ? i : j, idx2 = i > j ? i2 : j2;
687
+ return idx < 0 ? path : idx === idx2 ? path.slice(0, idx + 1) : path.slice(0, idx);
688
+ }(resourcePath) : null, pendingDependencyRequest = [];
689
+ loaderContext.parallel = !0, loaderContext.dependency = loaderContext.addDependency = function(file) {
690
+ pendingDependencyRequest.push(sendRequest("AddDependency", file));
691
+ }, loaderContext.addContextDependency = function(context) {
692
+ pendingDependencyRequest.push(sendRequest("AddContextDependency", context));
693
+ }, loaderContext.addMissingDependency = function(missing) {
694
+ pendingDependencyRequest.push(sendRequest("AddMissingDependency", missing));
695
+ }, loaderContext.addBuildDependency = function(file) {
696
+ pendingDependencyRequest.push(sendRequest("AddBuildDependency", file));
697
+ }, loaderContext.getDependencies = function() {
698
+ return waitForPendingRequest(pendingDependencyRequest), sendRequest("GetDependencies").wait();
699
+ }, loaderContext.getContextDependencies = function() {
700
+ return waitForPendingRequest(pendingDependencyRequest), sendRequest("GetContextDependencies").wait();
701
+ }, loaderContext.getMissingDependencies = function() {
702
+ return waitForPendingRequest(pendingDependencyRequest), sendRequest("GetMissingDependencies").wait();
703
+ }, loaderContext.clearDependencies = function() {
704
+ pendingDependencyRequest.push(sendRequest("ClearDependencies"));
705
+ }, loaderContext.resolve = function(context, request, callback) {
706
+ sendRequest("Resolve", context, request).then(([result, resolveRequest])=>{
707
+ callback(null, result, resolveRequest);
708
+ }, (err)=>{
709
+ callback(err);
710
+ });
711
+ }, loaderContext.getResolve = function(options) {
712
+ return function(context, request, callback) {
713
+ if (!callback) return new Promise((resolve, reject)=>{
714
+ sendRequest("GetResolve", options, context, request).then(([result])=>{
715
+ resolve(result);
716
+ }, (err)=>{
717
+ reject(err);
718
+ });
719
+ });
720
+ sendRequest("GetResolve", options, context, request).then(([result, resolveRequest])=>{
721
+ callback(null, result, resolveRequest);
722
+ }, (err)=>{
723
+ callback(err);
724
+ });
725
+ };
726
+ }, loaderContext.getLogger = function(name) {
727
+ return {
728
+ error (...args) {
729
+ sendRequest("GetLogger", 'error', name, args);
730
+ },
731
+ warn (...args) {
732
+ sendRequest("GetLogger", 'warn', name, args);
733
+ },
734
+ info (...args) {
735
+ sendRequest("GetLogger", 'info', name, args);
736
+ },
737
+ log (...args) {
738
+ sendRequest("GetLogger", 'log', name, args);
739
+ },
740
+ debug (...args) {
741
+ sendRequest("GetLogger", 'debug', name, args);
742
+ },
743
+ assert (assertion, ...args) {
744
+ assertion || sendRequest("GetLogger", 'error', name, args);
745
+ },
746
+ trace () {
747
+ sendRequest("GetLogger", 'trace', name, [
748
+ 'Trace'
749
+ ]);
750
+ },
751
+ clear () {
752
+ sendRequest("GetLogger", 'clear', name, []);
753
+ },
754
+ status (...args) {
755
+ sendRequest("GetLogger", 'status', name, args);
756
+ },
757
+ group (...args) {
758
+ sendRequest("GetLogger", 'group', name, args);
759
+ },
760
+ groupCollapsed (...args) {
761
+ sendRequest("GetLogger", 'groupCollapsed', name, args);
762
+ },
763
+ groupEnd (...args) {
764
+ sendRequest("GetLogger", 'groupEnd', name, args);
765
+ },
766
+ profile (label) {
767
+ sendRequest("GetLogger", 'profile', name, [
768
+ label
769
+ ]);
770
+ },
771
+ profileEnd (label) {
772
+ sendRequest("GetLogger", 'profileEnd', name, [
773
+ label
774
+ ]);
775
+ },
776
+ time (label) {
777
+ sendRequest("GetLogger", 'time', name, [
778
+ label
779
+ ]);
780
+ },
781
+ timeEnd (label) {
782
+ sendRequest("GetLogger", 'timeEnd', name, [
783
+ label
784
+ ]);
785
+ },
786
+ timeLog (label, ...args) {
787
+ sendRequest("GetLogger", 'timeLog', name, [
788
+ label,
789
+ ...args
790
+ ]);
791
+ },
792
+ timeAggregate (label) {
793
+ sendRequest("GetLogger", 'timeAggregate', name, [
794
+ label
795
+ ]);
796
+ },
797
+ timeAggregateEnd (label) {
798
+ sendRequest("GetLogger", 'timeAggregateEnd', name, [
799
+ label
800
+ ]);
801
+ }
802
+ };
803
+ }, loaderContext.emitError = function(err) {
804
+ sendRequest("EmitError", serializeError(err));
805
+ }, loaderContext.emitWarning = function(warning) {
806
+ sendRequest("EmitWarning", serializeError(warning));
807
+ }, loaderContext.emitFile = function(name, content, sourceMap, assetInfo) {
808
+ sendRequest("EmitFile", name, content, sourceMap, assetInfo);
809
+ }, loaderContext.experiments = {
810
+ emitDiagnostic (diagnostic) {
811
+ sendRequest("EmitDiagnostic", diagnostic);
812
+ }
813
+ };
814
+ let getAbsolutify = memoize(()=>absolutify.bindCache({})), getAbsolutifyInContext = memoize(()=>absolutify.bindContextCache(contextDirectory, {})), getContextify = memoize(()=>contextify.bindCache({})), getContextifyInContext = memoize(()=>contextify.bindContextCache(contextDirectory, {}));
815
+ loaderContext.utils = {
816
+ absolutify: (context, request)=>context === contextDirectory ? getAbsolutifyInContext()(request) : getAbsolutify()(context, request),
817
+ contextify: (context, request)=>context === contextDirectory ? getContextifyInContext()(request) : getContextify()(context, request),
818
+ createHash: (type)=>createHash_createHash(type || loaderContext._compilation.outputOptions.hashFunction)
819
+ }, loaderContext._compiler = {
820
+ ...loaderContext._compiler,
821
+ rspack: {
822
+ experiments: {
823
+ swc: swc_namespaceObject
824
+ }
825
+ },
826
+ webpack: {
827
+ util: {
828
+ createHash: createHash_createHash,
829
+ cleverMerge: cleverMerge
830
+ }
831
+ }
832
+ }, loaderContext._compilation = {
833
+ ...loaderContext._compilation,
834
+ getPath: (filename, data = {})=>(data.hash || (data = {
835
+ hash: loaderContext._compilation.hash ?? void 0,
836
+ ...data
837
+ }), sendRequest("CompilationGetPath", 'function' == typeof filename ? filename(data) : filename, data).wait()),
838
+ getPathWithInfo (filename, data = {}) {
839
+ data.hash || (data = {
840
+ hash: loaderContext._compilation.hash ?? void 0,
841
+ ...data
842
+ });
843
+ let info = {}, result = sendRequest("CompilationGetPathWithInfo", 'function' == typeof filename ? filename(data, info) : filename, data, info).wait();
844
+ return Object.assign(info, result.info), {
845
+ path: result.path,
846
+ info
847
+ };
848
+ },
849
+ getAssetPath: (filename, data = {})=>sendRequest("CompilationGetAssetPath", 'function' == typeof filename ? filename(data) : filename, data).wait(),
850
+ getAssetPathWithInfo (filename, data = {}) {
851
+ let info = {}, result = sendRequest("CompilationGetAssetPathWithInfo", 'function' == typeof filename ? filename(data, info) : filename, data, info).wait();
852
+ return Object.assign(info, result.info), {
853
+ path: result.path,
854
+ info
855
+ };
856
+ }
857
+ };
858
+ let _module = loaderContext._module, buildInfo = {
859
+ ..._module.buildInfo ?? {}
860
+ };
861
+ loaderContext._module = {
862
+ type: _module.type,
863
+ identifier: ()=>_module.identifier,
864
+ matchResource: _module.matchResource,
865
+ request: _module.request,
866
+ userRequest: _module.userRequest,
867
+ rawRequest: _module.rawRequest,
868
+ buildInfo
869
+ }, loaderContext.importModule = function(request, options, callback) {
870
+ if (!callback) return new Promise((resolve, reject)=>{
871
+ sendRequest("ImportModule", request, options).then((result)=>{
872
+ resolve(result);
873
+ }, (err)=>{
874
+ reject(err);
875
+ });
876
+ });
877
+ sendRequest("ImportModule", request, options).then((result)=>{
878
+ callback(null, result);
879
+ }, (err)=>{
880
+ callback(err);
881
+ });
882
+ }, loaderContext.fs = node_fs, Object.defineProperty(loaderContext, 'request', {
883
+ enumerable: !0,
884
+ get: ()=>loaderContext.loaders.map((o)=>o.request).concat(loaderContext.resource || '').join('!')
885
+ }), Object.defineProperty(loaderContext, 'remainingRequest', {
886
+ enumerable: !0,
887
+ get: ()=>loaderContext.loaderIndex >= loaderContext.loaders.length - 1 && !loaderContext.resource ? '' : loaderContext.loaders.slice(loaderContext.loaderIndex + 1).map((o)=>o.request).concat(loaderContext.resource || '').join('!')
888
+ }), Object.defineProperty(loaderContext, 'currentRequest', {
889
+ enumerable: !0,
890
+ get: ()=>loaderContext.loaders.slice(loaderContext.loaderIndex).map((o)=>o.request).concat(loaderContext.resource || '').join('!')
891
+ }), Object.defineProperty(loaderContext, 'previousRequest', {
892
+ enumerable: !0,
893
+ get: ()=>loaderContext.loaders.slice(0, loaderContext.loaderIndex).map((o)=>o.request).join('!')
894
+ }), Object.defineProperty(loaderContext, 'query', {
895
+ enumerable: !0,
896
+ get: ()=>{
897
+ let entry = loaderContext.loaders[loaderContext.loaderIndex];
898
+ return entry.options && 'object' == typeof entry.options ? entry.options : entry.query;
899
+ }
900
+ }), loaderContext.getOptions = function() {
901
+ let loader = function(loaderContext, index = loaderContext.loaderIndex) {
902
+ return loaderContext.loaders?.length && index < loaderContext.loaders.length && index >= 0 && loaderContext.loaders[index] ? loaderContext.loaders[index] : null;
903
+ }(loaderContext), options = loader?.options;
904
+ if ('string' == typeof options) if (options.startsWith('{') && options.endsWith('}')) try {
905
+ options = JSON.parse(options);
906
+ } catch (e) {
907
+ throw Error(`JSON parsing failed for loader's string options: ${e.message}`);
908
+ }
909
+ else options = node_querystring.parse(options);
910
+ return null == options && (options = {}), options;
911
+ }, loaderContext.cacheable = function(flag) {
912
+ !1 === flag && sendRequest("SetCacheable", !1);
913
+ }, Object.defineProperty(loaderContext, 'data', {
914
+ enumerable: !0,
915
+ get: ()=>loaderContext.loaders[loaderContext.loaderIndex].loaderItem.data,
916
+ set: (value)=>{
917
+ loaderContext.loaders[loaderContext.loaderIndex].loaderItem.data = value;
918
+ }
919
+ });
920
+ let shouldYieldToMainThread = (currentLoaderObject)=>!currentLoaderObject?.parallel;
921
+ switch(loaderState){
922
+ case binding_namespaceObject.JsLoaderState.Pitching:
923
+ for(; loaderContext.loaderIndex < loaderContext.loaderChainEnd;){
924
+ let currentLoaderObject = loaderContext.loaders[loaderContext.loaderIndex];
925
+ if (shouldYieldToMainThread(currentLoaderObject)) break;
926
+ if (currentLoaderObject.pitchExecuted) {
927
+ loaderContext.loaderIndex += 1;
928
+ continue;
929
+ }
930
+ await loadLoaderAsync(currentLoaderObject, loaderContext._compiler);
931
+ let fn = currentLoaderObject.pitch;
932
+ if ((currentLoaderObject.pitchExecuted = !0, fn) && (args = await utils_runSyncOrAsync(fn, loaderContext, [
933
+ loaderContext.remainingRequest,
934
+ loaderContext.previousRequest,
935
+ currentLoaderObject.loaderItem.data
936
+ ]) || []).some((value)=>void 0 !== value)) break;
937
+ }
938
+ break;
939
+ case binding_namespaceObject.JsLoaderState.Normal:
940
+ {
941
+ let codeFilterTextCache = {
942
+ initialized: !1
943
+ };
944
+ for(; loaderContext.loaderIndex >= loaderContext.loaderChainStart;){
945
+ let currentLoaderObject = loaderContext.loaders[loaderContext.loaderIndex];
946
+ if (currentLoaderObject.normalExecuted) {
947
+ loaderContext.loaderIndex--;
948
+ continue;
949
+ }
950
+ let { loaderItem } = currentLoaderObject, codeFilter = loaderItem.codeFilter;
951
+ if (codeFilter && !loaderItem.filterMatched) {
952
+ let matched = function(filter, content, cache) {
953
+ let code = function(content, cache) {
954
+ let text;
955
+ if (cache.initialized && cache.content === content) return cache.text ?? null;
956
+ if ('string' == typeof content) text = content;
957
+ else if (content instanceof Uint8Array) try {
958
+ text = decoder.decode(content);
959
+ } catch {
960
+ text = null;
961
+ }
962
+ else text = null;
963
+ return cache.initialized = !0, cache.content = content, cache.text = text, text;
964
+ }(content, cache);
965
+ if (null !== code) {
966
+ let matched;
967
+ return 'string' == typeof filter ? code.includes(filter) : (filter.lastIndex = 0, matched = filter.test(code), filter.lastIndex = 0, matched);
968
+ }
969
+ }(codeFilter, args[0], codeFilterTextCache);
970
+ if (!1 === matched) {
971
+ currentLoaderObject.normalExecuted = !0, loaderContext.loaderIndex--;
972
+ continue;
973
+ }
974
+ matched && (loaderItem.filterMatched = !0);
975
+ }
976
+ if (shouldYieldToMainThread(currentLoaderObject)) break;
977
+ await loadLoaderAsync(currentLoaderObject, loaderContext._compiler);
978
+ let fn = currentLoaderObject.normal;
979
+ currentLoaderObject.normalExecuted = !0, fn && (!function(args, raw) {
980
+ if (!raw && args[0] instanceof Uint8Array) {
981
+ var buf;
982
+ let isShared, str;
983
+ args[0] = (isShared = (buf = args[0]).buffer instanceof SharedArrayBuffer || buf.buffer.constructor?.name === 'SharedArrayBuffer', 0xfeff === (str = utils_decoder.decode(isShared ? Buffer.from(buf) : buf)).charCodeAt(0) ? str.slice(1) : str);
984
+ } else raw && 'string' == typeof args[0] && (args[0] = Buffer.from(args[0], 'utf-8'));
985
+ raw && args[0] instanceof Uint8Array && !Buffer.isBuffer(args[0]) && (args[0] = Buffer.from(args[0].buffer, args[0].byteOffset, args[0].byteLength));
986
+ }(args, !!currentLoaderObject.raw), args = await utils_runSyncOrAsync(fn, loaderContext, args) || [], codeFilterTextCache.initialized = !1, codeFilterTextCache.content = void 0, codeFilterTextCache.text = void 0);
987
+ }
988
+ }
989
+ }
990
+ return sendRequest("UpdateLoaderObjects", loaderContext.loaders.map((item)=>({
991
+ data: item.loaderItem.data,
992
+ normalExecuted: item.normalExecuted,
993
+ pitchExecuted: item.pitchExecuted,
994
+ filterMatched: item.loaderItem.filterMatched
995
+ }))), sendRequest("UpdateBuildInfo", buildInfo), args;
996
+ })(workerOptions, sendRequest1, waitFor).then((data)=>{
996
997
  workerData.workerPort.postMessage({
997
998
  type: 'done',
998
999
  data