@afterpack/integration-utils 0.2.0 → 0.2.1

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/index.cjs CHANGED
@@ -767,12 +767,16 @@ function warnIfPublicPath(artifactPath, logger = DEFAULT_LOGGER) {
767
767
  //#region src/source-map.ts
768
768
  const SOURCE_MAPPING_URL_RE = /\/\/[#@]\s*sourceMappingURL=(\S+)\s*$/gm;
769
769
  const SOURCE_MAPPING_URL_LINE_RE = /^[ \t]*\/\/[#@]\s*sourceMappingURL=\S+[ \t]*\r?\n?/gm;
770
+ const CSS_SOURCE_MAPPING_URL_RE = /[ \t]*\/\*[#@]\s*sourceMappingURL=[^\s*]+\s*\*\/\s*$/;
770
771
  function withSourceMappingURL(code, url) {
771
772
  const stripped = code.replace(SOURCE_MAPPING_URL_LINE_RE, "");
772
773
  if (url == null) return stripped;
773
774
  const separator = stripped.length > 0 && !stripped.endsWith("\n") ? "\n" : "";
774
775
  return `${stripped}${separator}//# sourceMappingURL=${url}\n`;
775
776
  }
777
+ function withoutCssSourceMappingURL(css) {
778
+ return css.replace(CSS_SOURCE_MAPPING_URL_RE, "");
779
+ }
776
780
  function extractSourceMappingURL(code) {
777
781
  let last = null;
778
782
  for (const match of code.matchAll(SOURCE_MAPPING_URL_RE)) last = match[1];
@@ -826,6 +830,7 @@ function discoverInputSourceMap(jsPath, code) {
826
830
  //#endregion
827
831
  //#region src/bundle.ts
828
832
  const BUNDLE_JS_RE = /\.[cm]?js$/;
833
+ const CSS_MAP_RE = /\.css\.map$/;
829
834
  function collectBundleJs(bundle, outDir) {
830
835
  const files = [];
831
836
  const inputs = new Map();
@@ -871,6 +876,18 @@ function applyBundleOutput(bundle, entry, out, policy) {
871
876
  }
872
877
  entry.code = withSourceMappingURL(out.code, policy.emitSourceMappingURL ? url : null);
873
878
  }
879
+ function stripBundleCssSourceMaps(bundle) {
880
+ for (const [fileName, entry] of Object.entries(bundle)) {
881
+ if (CSS_MAP_RE.test(fileName)) {
882
+ delete bundle[fileName];
883
+ continue;
884
+ }
885
+ if (entry.type !== "asset" || !fileName.endsWith(".css") || entry.source === void 0) continue;
886
+ const css = typeof entry.source === "string" ? entry.source : Buffer.from(entry.source).toString("utf8");
887
+ const stripped = withoutCssSourceMappingURL(css);
888
+ if (stripped !== css) entry.source = stripped;
889
+ }
890
+ }
874
891
 
875
892
  //#endregion
876
893
  //#region src/glob.ts
@@ -1003,10 +1020,8 @@ function walkJs(dir, include, readmitted, onNestedProject) {
1003
1020
  }
1004
1021
  return out;
1005
1022
  }
1006
- function isSourceMap(name) {
1007
- return name.endsWith(".js.map") || name.endsWith(".mjs.map") || name.endsWith(".cjs.map");
1008
- }
1009
- function collectSourceMaps(dir) {
1023
+ const SOURCE_MAP_RE = /\.(?:[cm]?js|css)\.map$/;
1024
+ function collectFiles(dir, accept) {
1010
1025
  if (!(0, node_fs.existsSync)(dir)) return [];
1011
1026
  const out = [];
1012
1027
  for (const entry of entriesOf(dir)) {
@@ -1014,11 +1029,17 @@ function collectSourceMaps(dir) {
1014
1029
  const full = (0, node_path.join)(dir, name);
1015
1030
  const kind = kindOf(entry, full);
1016
1031
  if (kind === null) continue;
1017
- if (kind === "dir") out.push(...collectSourceMaps(full));
1018
- else if (isSourceMap(name)) out.push(full);
1032
+ if (kind === "dir") out.push(...collectFiles(full, accept));
1033
+ else if (accept(name)) out.push(full);
1019
1034
  }
1020
1035
  return out;
1021
1036
  }
1037
+ function collectSourceMaps(dir) {
1038
+ return collectFiles(dir, (name) => SOURCE_MAP_RE.test(name));
1039
+ }
1040
+ function collectStylesheets(dir) {
1041
+ return collectFiles(dir, (name) => name.endsWith(".css"));
1042
+ }
1022
1043
 
1023
1044
  //#endregion
1024
1045
  //#region src/notices.ts
@@ -1383,7 +1404,7 @@ const CONFIG_KEYS = [
1383
1404
  tier: "free",
1384
1405
  surface: "engine",
1385
1406
  item: { kind: "boolean" },
1386
- default: "true when the bundler emitted a source map"
1407
+ default: "true when the bundler emitted a source map, outside CI"
1387
1408
  },
1388
1409
  {
1389
1410
  path: "protectionMap.detailed",
@@ -4613,6 +4634,7 @@ exports.applyResolvedKey = applyResolvedKey;
4613
4634
  exports.collectBundleJs = collectBundleJs;
4614
4635
  exports.collectJsFiles = collectJsFiles;
4615
4636
  exports.collectSourceMaps = collectSourceMaps;
4637
+ exports.collectStylesheets = collectStylesheets;
4616
4638
  exports.createTelemetryReporter = createTelemetryReporter;
4617
4639
  exports.decodeDataUri = decodeDataUri;
4618
4640
  exports.discoverInputSourceMap = discoverInputSourceMap;
@@ -4636,11 +4658,13 @@ exports.sanitizeNotices = sanitizeNotices;
4636
4658
  exports.scanDirectives = scanDirectives;
4637
4659
  exports.serverAddsInfo = serverAddsInfo;
4638
4660
  exports.sha256Of = sha256Of;
4661
+ exports.stripBundleCssSourceMaps = stripBundleCssSourceMaps;
4639
4662
  exports.toEngineConfig = toEngineConfig;
4640
4663
  exports.toPluginOptions = toPluginOptions;
4641
4664
  exports.validateConfig = validateConfig;
4642
4665
  exports.verifyProtectionReceipt = verifyProtectionReceipt;
4643
4666
  exports.withSourceMappingURL = withSourceMappingURL;
4667
+ exports.withoutCssSourceMappingURL = withoutCssSourceMappingURL;
4644
4668
  exports.writeArtifacts = writeArtifacts;
4645
4669
  exports.writeDeferredProtectionReceipt = writeDeferredProtectionReceipt;
4646
4670
  exports.writeProtectionReceipt = writeProtectionReceipt;
package/dist/index.d.cts CHANGED
@@ -260,7 +260,7 @@ declare const CONFIG_KEYS: readonly [{
260
260
  readonly item: {
261
261
  readonly kind: "boolean";
262
262
  };
263
- readonly default: "true when the bundler emitted a source map";
263
+ readonly default: "true when the bundler emitted a source map, outside CI";
264
264
  }, {
265
265
  readonly path: "protectionMap.detailed";
266
266
  readonly shape: "scalar";
@@ -1075,6 +1075,7 @@ interface BundleJs {
1075
1075
  }
1076
1076
  declare function collectBundleJs(bundle: OutputBundleLike, outDir: string): BundleJs;
1077
1077
  declare function applyBundleOutput(bundle: OutputBundleLike, entry: BundleEntryLike, out: InMemoryOutput, policy: ReportPolicy): void;
1078
+ declare function stripBundleCssSourceMaps(bundle: OutputBundleLike): void;
1078
1079
  //#endregion
1079
1080
  //#region src/collect.d.ts
1080
1081
  interface CollectJsOptions {
@@ -1083,6 +1084,7 @@ interface CollectJsOptions {
1083
1084
  }
1084
1085
  declare function collectJsFiles(target: string, options?: CollectJsOptions): string[];
1085
1086
  declare function collectSourceMaps(dir: string): string[];
1087
+ declare function collectStylesheets(dir: string): string[];
1086
1088
  //#endregion
1087
1089
  //#region src/config-file.d.ts
1088
1090
  declare const CONFIG_FILE_NAME = "afterpack.json";
@@ -1141,8 +1143,9 @@ declare function resolvePluginConfig(input: PluginConfigInput): ResolvedPluginCo
1141
1143
  //#endregion
1142
1144
  //#region src/source-map.d.ts
1143
1145
  declare function withSourceMappingURL(code: string, url: string | null): string;
1146
+ declare function withoutCssSourceMappingURL(css: string): string;
1144
1147
  declare function extractSourceMappingURL(code: string): string | null;
1145
1148
  declare function decodeDataUri(url: string): string | null;
1146
1149
  declare function discoverInputSourceMap(jsPath: string, code?: string): string | null;
1147
1150
  //#endregion
1148
- export { type AfterpackArtifactOptions, type AfterpackConfig, type AfterpackPluginOptions, AlreadyObfuscatedError, type ArtifactMode, type BuildContext, type BuildEngineConfigOptions, type BundleEntryLike, type BundleJs, CLOUD_REFUSAL_SUMMARY, CONFIG_FILE_NAME, CONFIG_KEYS, CORE_FLOOR_SUMMARY, type CapturedDirective, type CapturedModule, type CliParseResult, type ClientIdentity, CloudApiError, type CloudErrorKind, type CloudNotice, type CollectJsOptions, type CombinedProtectionMapTarget, type ConfigIssue, type ConfigKeyDef, type ConfigScope, type ConfigSurface, type ConfigTier, type CoreConfig, type CoreConfigSubset, CoreVersionError, DIAG_ALREADY_OBFUSCATED, DIAG_RECEIPT_UNREADABLE, type DiagnosticsSummary, type DiagnosticsVerbosity, type DirectiveDiagnostic, type DirectiveManifest, type EngineBatchResult, type EngineDiagnostic, type EngineDiagnosticData, type EngineFileInput, type EngineFileResult, type EngineSeverity, type EngineSpan, type EnvLike, type EnvParseResult, type GitBuildContext, type GlobReserved, type InMemoryInput, type InMemoryOutput, type LoadedConfigFile, type Logger, type NormalizedPluginOptions, type NoticeLogger, type NoticeSeverity, type ObfuscationEngine, type ObfuscationPassOptions, type ObfuscationPassResult, type OutputBundleLike, PROTECTION_RECEIPT_FILE, type PassMessages, type PassReceiptIdentity, type PassSettings, type PassTiming, type PluginConfigInput, type PluginOptionsView, type Preset, type ProtectionReceipt, type ProtectionReceiptFile, type ProtectionVerification, type RegionConfig, type ReportPolicy, type ReportPolicySignals, type ResolvedPluginConfig, SEED_ENV_VAR, type SafeNotice, type SeedOption, type SeedOrigin, type TelemetryContext, type TelemetryDiagnostic, type TelemetryDiagnosticData, type TelemetryFacts, type TelemetryPayload, type TelemetryReporter, type TelemetryReporterDeps, type TelemetrySeverity, type TelemetrySpan, type TransformKind, UnreadableReceiptError, type ValidationResult, type ValueShape, type ValueType, type WriteArtifactsInput, type WriteArtifactsResult, type WriteProtectionReceiptInput, applyBundleOutput, applyResolvedKey, collectBundleJs, collectJsFiles, collectSourceMaps, createTelemetryReporter, decodeDataUri, discoverInputSourceMap, ensureAfterpackGitignore, extractSourceMappingURL, findUpward, getPath, installedRequiredLine, loadConfigFile, mergeConfig, normalizePluginOptions, npxAlternative, parseCliOptions, parseEnvOptions, passSettings, resolveClientIdentity, resolvePluginConfig, resolveReportPolicy, runObfuscationPass, sanitizeNotices, scanDirectives, serverAddsInfo, sha256Of, toEngineConfig, toPluginOptions, validateConfig, verifyProtectionReceipt, withSourceMappingURL, writeArtifacts, writeDeferredProtectionReceipt, writeProtectionReceipt };
1151
+ export { type AfterpackArtifactOptions, type AfterpackConfig, type AfterpackPluginOptions, AlreadyObfuscatedError, type ArtifactMode, type BuildContext, type BuildEngineConfigOptions, type BundleEntryLike, type BundleJs, CLOUD_REFUSAL_SUMMARY, CONFIG_FILE_NAME, CONFIG_KEYS, CORE_FLOOR_SUMMARY, type CapturedDirective, type CapturedModule, type CliParseResult, type ClientIdentity, CloudApiError, type CloudErrorKind, type CloudNotice, type CollectJsOptions, type CombinedProtectionMapTarget, type ConfigIssue, type ConfigKeyDef, type ConfigScope, type ConfigSurface, type ConfigTier, type CoreConfig, type CoreConfigSubset, CoreVersionError, DIAG_ALREADY_OBFUSCATED, DIAG_RECEIPT_UNREADABLE, type DiagnosticsSummary, type DiagnosticsVerbosity, type DirectiveDiagnostic, type DirectiveManifest, type EngineBatchResult, type EngineDiagnostic, type EngineDiagnosticData, type EngineFileInput, type EngineFileResult, type EngineSeverity, type EngineSpan, type EnvLike, type EnvParseResult, type GitBuildContext, type GlobReserved, type InMemoryInput, type InMemoryOutput, type LoadedConfigFile, type Logger, type NormalizedPluginOptions, type NoticeLogger, type NoticeSeverity, type ObfuscationEngine, type ObfuscationPassOptions, type ObfuscationPassResult, type OutputBundleLike, PROTECTION_RECEIPT_FILE, type PassMessages, type PassReceiptIdentity, type PassSettings, type PassTiming, type PluginConfigInput, type PluginOptionsView, type Preset, type ProtectionReceipt, type ProtectionReceiptFile, type ProtectionVerification, type RegionConfig, type ReportPolicy, type ReportPolicySignals, type ResolvedPluginConfig, SEED_ENV_VAR, type SafeNotice, type SeedOption, type SeedOrigin, type TelemetryContext, type TelemetryDiagnostic, type TelemetryDiagnosticData, type TelemetryFacts, type TelemetryPayload, type TelemetryReporter, type TelemetryReporterDeps, type TelemetrySeverity, type TelemetrySpan, type TransformKind, UnreadableReceiptError, type ValidationResult, type ValueShape, type ValueType, type WriteArtifactsInput, type WriteArtifactsResult, type WriteProtectionReceiptInput, applyBundleOutput, applyResolvedKey, collectBundleJs, collectJsFiles, collectSourceMaps, collectStylesheets, createTelemetryReporter, decodeDataUri, discoverInputSourceMap, ensureAfterpackGitignore, extractSourceMappingURL, findUpward, getPath, installedRequiredLine, loadConfigFile, mergeConfig, normalizePluginOptions, npxAlternative, parseCliOptions, parseEnvOptions, passSettings, resolveClientIdentity, resolvePluginConfig, resolveReportPolicy, runObfuscationPass, sanitizeNotices, scanDirectives, serverAddsInfo, sha256Of, stripBundleCssSourceMaps, toEngineConfig, toPluginOptions, validateConfig, verifyProtectionReceipt, withSourceMappingURL, withoutCssSourceMappingURL, writeArtifacts, writeDeferredProtectionReceipt, writeProtectionReceipt };
package/dist/index.d.ts CHANGED
@@ -260,7 +260,7 @@ declare const CONFIG_KEYS: readonly [{
260
260
  readonly item: {
261
261
  readonly kind: "boolean";
262
262
  };
263
- readonly default: "true when the bundler emitted a source map";
263
+ readonly default: "true when the bundler emitted a source map, outside CI";
264
264
  }, {
265
265
  readonly path: "protectionMap.detailed";
266
266
  readonly shape: "scalar";
@@ -1075,6 +1075,7 @@ interface BundleJs {
1075
1075
  }
1076
1076
  declare function collectBundleJs(bundle: OutputBundleLike, outDir: string): BundleJs;
1077
1077
  declare function applyBundleOutput(bundle: OutputBundleLike, entry: BundleEntryLike, out: InMemoryOutput, policy: ReportPolicy): void;
1078
+ declare function stripBundleCssSourceMaps(bundle: OutputBundleLike): void;
1078
1079
  //#endregion
1079
1080
  //#region src/collect.d.ts
1080
1081
  interface CollectJsOptions {
@@ -1083,6 +1084,7 @@ interface CollectJsOptions {
1083
1084
  }
1084
1085
  declare function collectJsFiles(target: string, options?: CollectJsOptions): string[];
1085
1086
  declare function collectSourceMaps(dir: string): string[];
1087
+ declare function collectStylesheets(dir: string): string[];
1086
1088
  //#endregion
1087
1089
  //#region src/config-file.d.ts
1088
1090
  declare const CONFIG_FILE_NAME = "afterpack.json";
@@ -1141,8 +1143,9 @@ declare function resolvePluginConfig(input: PluginConfigInput): ResolvedPluginCo
1141
1143
  //#endregion
1142
1144
  //#region src/source-map.d.ts
1143
1145
  declare function withSourceMappingURL(code: string, url: string | null): string;
1146
+ declare function withoutCssSourceMappingURL(css: string): string;
1144
1147
  declare function extractSourceMappingURL(code: string): string | null;
1145
1148
  declare function decodeDataUri(url: string): string | null;
1146
1149
  declare function discoverInputSourceMap(jsPath: string, code?: string): string | null;
1147
1150
  //#endregion
1148
- export { type AfterpackArtifactOptions, type AfterpackConfig, type AfterpackPluginOptions, AlreadyObfuscatedError, type ArtifactMode, type BuildContext, type BuildEngineConfigOptions, type BundleEntryLike, type BundleJs, CLOUD_REFUSAL_SUMMARY, CONFIG_FILE_NAME, CONFIG_KEYS, CORE_FLOOR_SUMMARY, type CapturedDirective, type CapturedModule, type CliParseResult, type ClientIdentity, CloudApiError, type CloudErrorKind, type CloudNotice, type CollectJsOptions, type CombinedProtectionMapTarget, type ConfigIssue, type ConfigKeyDef, type ConfigScope, type ConfigSurface, type ConfigTier, type CoreConfig, type CoreConfigSubset, CoreVersionError, DIAG_ALREADY_OBFUSCATED, DIAG_RECEIPT_UNREADABLE, type DiagnosticsSummary, type DiagnosticsVerbosity, type DirectiveDiagnostic, type DirectiveManifest, type EngineBatchResult, type EngineDiagnostic, type EngineDiagnosticData, type EngineFileInput, type EngineFileResult, type EngineSeverity, type EngineSpan, type EnvLike, type EnvParseResult, type GitBuildContext, type GlobReserved, type InMemoryInput, type InMemoryOutput, type LoadedConfigFile, type Logger, type NormalizedPluginOptions, type NoticeLogger, type NoticeSeverity, type ObfuscationEngine, type ObfuscationPassOptions, type ObfuscationPassResult, type OutputBundleLike, PROTECTION_RECEIPT_FILE, type PassMessages, type PassReceiptIdentity, type PassSettings, type PassTiming, type PluginConfigInput, type PluginOptionsView, type Preset, type ProtectionReceipt, type ProtectionReceiptFile, type ProtectionVerification, type RegionConfig, type ReportPolicy, type ReportPolicySignals, type ResolvedPluginConfig, SEED_ENV_VAR, type SafeNotice, type SeedOption, type SeedOrigin, type TelemetryContext, type TelemetryDiagnostic, type TelemetryDiagnosticData, type TelemetryFacts, type TelemetryPayload, type TelemetryReporter, type TelemetryReporterDeps, type TelemetrySeverity, type TelemetrySpan, type TransformKind, UnreadableReceiptError, type ValidationResult, type ValueShape, type ValueType, type WriteArtifactsInput, type WriteArtifactsResult, type WriteProtectionReceiptInput, applyBundleOutput, applyResolvedKey, collectBundleJs, collectJsFiles, collectSourceMaps, createTelemetryReporter, decodeDataUri, discoverInputSourceMap, ensureAfterpackGitignore, extractSourceMappingURL, findUpward, getPath, installedRequiredLine, loadConfigFile, mergeConfig, normalizePluginOptions, npxAlternative, parseCliOptions, parseEnvOptions, passSettings, resolveClientIdentity, resolvePluginConfig, resolveReportPolicy, runObfuscationPass, sanitizeNotices, scanDirectives, serverAddsInfo, sha256Of, toEngineConfig, toPluginOptions, validateConfig, verifyProtectionReceipt, withSourceMappingURL, writeArtifacts, writeDeferredProtectionReceipt, writeProtectionReceipt };
1151
+ export { type AfterpackArtifactOptions, type AfterpackConfig, type AfterpackPluginOptions, AlreadyObfuscatedError, type ArtifactMode, type BuildContext, type BuildEngineConfigOptions, type BundleEntryLike, type BundleJs, CLOUD_REFUSAL_SUMMARY, CONFIG_FILE_NAME, CONFIG_KEYS, CORE_FLOOR_SUMMARY, type CapturedDirective, type CapturedModule, type CliParseResult, type ClientIdentity, CloudApiError, type CloudErrorKind, type CloudNotice, type CollectJsOptions, type CombinedProtectionMapTarget, type ConfigIssue, type ConfigKeyDef, type ConfigScope, type ConfigSurface, type ConfigTier, type CoreConfig, type CoreConfigSubset, CoreVersionError, DIAG_ALREADY_OBFUSCATED, DIAG_RECEIPT_UNREADABLE, type DiagnosticsSummary, type DiagnosticsVerbosity, type DirectiveDiagnostic, type DirectiveManifest, type EngineBatchResult, type EngineDiagnostic, type EngineDiagnosticData, type EngineFileInput, type EngineFileResult, type EngineSeverity, type EngineSpan, type EnvLike, type EnvParseResult, type GitBuildContext, type GlobReserved, type InMemoryInput, type InMemoryOutput, type LoadedConfigFile, type Logger, type NormalizedPluginOptions, type NoticeLogger, type NoticeSeverity, type ObfuscationEngine, type ObfuscationPassOptions, type ObfuscationPassResult, type OutputBundleLike, PROTECTION_RECEIPT_FILE, type PassMessages, type PassReceiptIdentity, type PassSettings, type PassTiming, type PluginConfigInput, type PluginOptionsView, type Preset, type ProtectionReceipt, type ProtectionReceiptFile, type ProtectionVerification, type RegionConfig, type ReportPolicy, type ReportPolicySignals, type ResolvedPluginConfig, SEED_ENV_VAR, type SafeNotice, type SeedOption, type SeedOrigin, type TelemetryContext, type TelemetryDiagnostic, type TelemetryDiagnosticData, type TelemetryFacts, type TelemetryPayload, type TelemetryReporter, type TelemetryReporterDeps, type TelemetrySeverity, type TelemetrySpan, type TransformKind, UnreadableReceiptError, type ValidationResult, type ValueShape, type ValueType, type WriteArtifactsInput, type WriteArtifactsResult, type WriteProtectionReceiptInput, applyBundleOutput, applyResolvedKey, collectBundleJs, collectJsFiles, collectSourceMaps, collectStylesheets, createTelemetryReporter, decodeDataUri, discoverInputSourceMap, ensureAfterpackGitignore, extractSourceMappingURL, findUpward, getPath, installedRequiredLine, loadConfigFile, mergeConfig, normalizePluginOptions, npxAlternative, parseCliOptions, parseEnvOptions, passSettings, resolveClientIdentity, resolvePluginConfig, resolveReportPolicy, runObfuscationPass, sanitizeNotices, scanDirectives, serverAddsInfo, sha256Of, stripBundleCssSourceMaps, toEngineConfig, toPluginOptions, validateConfig, verifyProtectionReceipt, withSourceMappingURL, withoutCssSourceMappingURL, writeArtifacts, writeDeferredProtectionReceipt, writeProtectionReceipt };
package/dist/index.js CHANGED
@@ -478,12 +478,16 @@ function warnIfPublicPath(artifactPath, logger = DEFAULT_LOGGER) {
478
478
  //#region src/source-map.ts
479
479
  const SOURCE_MAPPING_URL_RE = /\/\/[#@]\s*sourceMappingURL=(\S+)\s*$/gm;
480
480
  const SOURCE_MAPPING_URL_LINE_RE = /^[ \t]*\/\/[#@]\s*sourceMappingURL=\S+[ \t]*\r?\n?/gm;
481
+ const CSS_SOURCE_MAPPING_URL_RE = /[ \t]*\/\*[#@]\s*sourceMappingURL=[^\s*]+\s*\*\/\s*$/;
481
482
  function withSourceMappingURL(code, url) {
482
483
  const stripped = code.replace(SOURCE_MAPPING_URL_LINE_RE, "");
483
484
  if (url == null) return stripped;
484
485
  const separator = stripped.length > 0 && !stripped.endsWith("\n") ? "\n" : "";
485
486
  return `${stripped}${separator}//# sourceMappingURL=${url}\n`;
486
487
  }
488
+ function withoutCssSourceMappingURL(css) {
489
+ return css.replace(CSS_SOURCE_MAPPING_URL_RE, "");
490
+ }
487
491
  function extractSourceMappingURL(code) {
488
492
  let last = null;
489
493
  for (const match of code.matchAll(SOURCE_MAPPING_URL_RE)) last = match[1];
@@ -537,6 +541,7 @@ function discoverInputSourceMap(jsPath, code) {
537
541
  //#endregion
538
542
  //#region src/bundle.ts
539
543
  const BUNDLE_JS_RE = /\.[cm]?js$/;
544
+ const CSS_MAP_RE = /\.css\.map$/;
540
545
  function collectBundleJs(bundle, outDir) {
541
546
  const files = [];
542
547
  const inputs = new Map();
@@ -582,6 +587,18 @@ function applyBundleOutput(bundle, entry, out, policy) {
582
587
  }
583
588
  entry.code = withSourceMappingURL(out.code, policy.emitSourceMappingURL ? url : null);
584
589
  }
590
+ function stripBundleCssSourceMaps(bundle) {
591
+ for (const [fileName, entry] of Object.entries(bundle)) {
592
+ if (CSS_MAP_RE.test(fileName)) {
593
+ delete bundle[fileName];
594
+ continue;
595
+ }
596
+ if (entry.type !== "asset" || !fileName.endsWith(".css") || entry.source === void 0) continue;
597
+ const css = typeof entry.source === "string" ? entry.source : Buffer.from(entry.source).toString("utf8");
598
+ const stripped = withoutCssSourceMappingURL(css);
599
+ if (stripped !== css) entry.source = stripped;
600
+ }
601
+ }
585
602
 
586
603
  //#endregion
587
604
  //#region src/glob.ts
@@ -714,10 +731,8 @@ function walkJs(dir, include, readmitted, onNestedProject) {
714
731
  }
715
732
  return out;
716
733
  }
717
- function isSourceMap(name) {
718
- return name.endsWith(".js.map") || name.endsWith(".mjs.map") || name.endsWith(".cjs.map");
719
- }
720
- function collectSourceMaps(dir) {
734
+ const SOURCE_MAP_RE = /\.(?:[cm]?js|css)\.map$/;
735
+ function collectFiles(dir, accept) {
721
736
  if (!existsSync(dir)) return [];
722
737
  const out = [];
723
738
  for (const entry of entriesOf(dir)) {
@@ -725,11 +740,17 @@ function collectSourceMaps(dir) {
725
740
  const full = join(dir, name);
726
741
  const kind = kindOf(entry, full);
727
742
  if (kind === null) continue;
728
- if (kind === "dir") out.push(...collectSourceMaps(full));
729
- else if (isSourceMap(name)) out.push(full);
743
+ if (kind === "dir") out.push(...collectFiles(full, accept));
744
+ else if (accept(name)) out.push(full);
730
745
  }
731
746
  return out;
732
747
  }
748
+ function collectSourceMaps(dir) {
749
+ return collectFiles(dir, (name) => SOURCE_MAP_RE.test(name));
750
+ }
751
+ function collectStylesheets(dir) {
752
+ return collectFiles(dir, (name) => name.endsWith(".css"));
753
+ }
733
754
 
734
755
  //#endregion
735
756
  //#region src/notices.ts
@@ -1094,7 +1115,7 @@ const CONFIG_KEYS = [
1094
1115
  tier: "free",
1095
1116
  surface: "engine",
1096
1117
  item: { kind: "boolean" },
1097
- default: "true when the bundler emitted a source map"
1118
+ default: "true when the bundler emitted a source map, outside CI"
1098
1119
  },
1099
1120
  {
1100
1121
  path: "protectionMap.detailed",
@@ -4307,4 +4328,4 @@ function resolvePluginConfig(input) {
4307
4328
  }
4308
4329
 
4309
4330
  //#endregion
4310
- export { AlreadyObfuscatedError, CLOUD_REFUSAL_SUMMARY, CONFIG_FILE_NAME, CONFIG_KEYS, CORE_FLOOR_SUMMARY, CloudApiError, CoreVersionError, DIAG_ALREADY_OBFUSCATED, DIAG_RECEIPT_UNREADABLE, PROTECTION_RECEIPT_FILE, SEED_ENV_VAR, UnreadableReceiptError, applyBundleOutput, applyResolvedKey, collectBundleJs, collectJsFiles, collectSourceMaps, createTelemetryReporter, decodeDataUri, discoverInputSourceMap, ensureAfterpackGitignore, extractSourceMappingURL, findUpward, getPath, installedRequiredLine, loadConfigFile, mergeConfig, normalizePluginOptions, npxAlternative, parseCliOptions, parseEnvOptions, passSettings, resolveClientIdentity, resolvePluginConfig, resolveReportPolicy, runObfuscationPass, sanitizeNotices, scanDirectives, serverAddsInfo, sha256Of, toEngineConfig, toPluginOptions, validateConfig, verifyProtectionReceipt, withSourceMappingURL, writeArtifacts, writeDeferredProtectionReceipt, writeProtectionReceipt };
4331
+ export { AlreadyObfuscatedError, CLOUD_REFUSAL_SUMMARY, CONFIG_FILE_NAME, CONFIG_KEYS, CORE_FLOOR_SUMMARY, CloudApiError, CoreVersionError, DIAG_ALREADY_OBFUSCATED, DIAG_RECEIPT_UNREADABLE, PROTECTION_RECEIPT_FILE, SEED_ENV_VAR, UnreadableReceiptError, applyBundleOutput, applyResolvedKey, collectBundleJs, collectJsFiles, collectSourceMaps, collectStylesheets, createTelemetryReporter, decodeDataUri, discoverInputSourceMap, ensureAfterpackGitignore, extractSourceMappingURL, findUpward, getPath, installedRequiredLine, loadConfigFile, mergeConfig, normalizePluginOptions, npxAlternative, parseCliOptions, parseEnvOptions, passSettings, resolveClientIdentity, resolvePluginConfig, resolveReportPolicy, runObfuscationPass, sanitizeNotices, scanDirectives, serverAddsInfo, sha256Of, stripBundleCssSourceMaps, toEngineConfig, toPluginOptions, validateConfig, verifyProtectionReceipt, withSourceMappingURL, withoutCssSourceMappingURL, writeArtifacts, writeDeferredProtectionReceipt, writeProtectionReceipt };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afterpack/integration-utils",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Internal shared code for the AfterPack CLI and framework plugins",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -26,7 +26,7 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "@jridgewell/sourcemap-codec": "^1.5.5",
29
- "@afterpack/protection-map": "0.2.0"
29
+ "@afterpack/protection-map": "0.2.1"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@biomejs/biome": "2.4.4",