@afterpack/integration-utils 0.2.3 → 0.2.4

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.d.cts CHANGED
@@ -244,7 +244,7 @@ declare const CONFIG_KEYS: readonly [{
244
244
  readonly item: {
245
245
  readonly kind: "boolean";
246
246
  };
247
- readonly default: "true in development when an input map exists; false in production";
247
+ readonly default: "false; true in development mode when an input map exists";
248
248
  }, {
249
249
  readonly path: "sourceMap.sourcesContent";
250
250
  readonly shape: "scalar";
@@ -254,7 +254,7 @@ declare const CONFIG_KEYS: readonly [{
254
254
  readonly item: {
255
255
  readonly kind: "boolean";
256
256
  };
257
- readonly default: "true in development; false in production";
257
+ readonly default: "false; true in development mode";
258
258
  }, {
259
259
  readonly path: "sourceMap.emitUrl";
260
260
  readonly shape: "scalar";
@@ -264,7 +264,7 @@ declare const CONFIG_KEYS: readonly [{
264
264
  readonly item: {
265
265
  readonly kind: "boolean";
266
266
  };
267
- readonly default: "true in development; false in production";
267
+ readonly default: "false; true in development mode";
268
268
  }, {
269
269
  readonly path: "protectionMap.enabled";
270
270
  readonly shape: "scalar";
@@ -416,7 +416,7 @@ declare const CONFIG_KEYS: readonly [{
416
416
  readonly kind: "enum";
417
417
  readonly values: readonly ["production", "development"];
418
418
  };
419
- readonly default: "detected from the environment";
419
+ readonly default: "production, unless NODE_ENV is development";
420
420
  }, {
421
421
  readonly path: "directives.enabled";
422
422
  readonly shape: "scalar";
@@ -682,7 +682,7 @@ interface WriteArtifactsInput {
682
682
  originalSource: string | null;
683
683
  policy: ReportPolicy;
684
684
  mode?: ArtifactMode;
685
- afterpackDir?: string;
685
+ afterpackDir: string;
686
686
  logger?: Logger;
687
687
  }
688
688
  interface WriteArtifactsResult {
@@ -794,6 +794,94 @@ declare class AlreadyObfuscatedError extends Error {
794
794
  constructor(message: string, files: readonly string[], receiptPath: string, dir: string);
795
795
  }
796
796
  //#endregion
797
+ //#region src/plugin-config.d.ts
798
+ declare const PLUGIN_LOCAL_KEYS: readonly ["git"];
799
+ type AfterpackPluginOptions = Omit<AfterpackConfig, "key"> & Pick<AfterpackArtifactOptions, (typeof PLUGIN_LOCAL_KEYS)[number]>;
800
+ interface NormalizedPluginOptions {
801
+ config: Record<string, unknown>;
802
+ issues: ConfigIssue[];
803
+ }
804
+ declare function normalizePluginOptions(input: unknown, localKeys: readonly string[], surface: string): NormalizedPluginOptions;
805
+ interface PluginConfigInput {
806
+ label: string;
807
+ options?: unknown;
808
+ argv?: string[];
809
+ cwd?: string;
810
+ env?: Record<string, string | undefined>;
811
+ localKeys?: readonly string[];
812
+ unsupported?: Readonly<Record<string, string>>;
813
+ }
814
+ interface ResolvedPluginConfig {
815
+ config: AfterpackConfig;
816
+ options: PluginOptionsView;
817
+ engineConfig: CoreConfigSubset;
818
+ configFile: string | null;
819
+ positionals: string[];
820
+ help: boolean;
821
+ version: boolean;
822
+ }
823
+ type PassSettings = Pick<ObfuscationPassOptions, "artifactOptions" | "seed" | "preset" | "complexity" | "regions" | "engineConfig" | "diagnostics" | "directivesEnabled" | "directivesEnabledExplicit">;
824
+ declare function passSettings(resolved: Pick<ResolvedPluginConfig, "options" | "engineConfig">): PassSettings;
825
+ declare function applyResolvedKey(config: AfterpackConfig, env?: Record<string, string | undefined>): void;
826
+ declare function resolvePluginConfig(input: PluginConfigInput): ResolvedPluginConfig;
827
+ //#endregion
828
+ //#region src/seed.d.ts
829
+ type SeedOption = number | string | undefined;
830
+ declare const SEED_ENV_VAR = "AFTERPACK_SEED";
831
+ type SeedOrigin = "option" | "git" | "env" | "session" | "fresh";
832
+ interface ResolvedBuildSeed {
833
+ seed: number | string;
834
+ origin: SeedOrigin;
835
+ legs: string[];
836
+ generation: number;
837
+ mismatch: {
838
+ leg: string;
839
+ seed: number | string;
840
+ } | null;
841
+ }
842
+ //#endregion
843
+ //#region src/hash-salt.d.ts
844
+ interface SaltEngine {
845
+ engineVersion: string | null;
846
+ nonce: string | null;
847
+ cloud: boolean;
848
+ probedCloudVersion: string | null;
849
+ probeFailed: boolean;
850
+ }
851
+ declare function saltSettings(settings: PassSettings, extra?: Record<string, unknown>): unknown;
852
+ interface ReportPolicySaltBits {
853
+ sourceMap: boolean;
854
+ emitSourceMappingURL: boolean;
855
+ }
856
+ declare function reportPolicySaltBits(env: Record<string, string | undefined>, artifactOptions: PassSettings["artifactOptions"], hasBundlerSourcemap: boolean): ReportPolicySaltBits;
857
+ interface PreparedHashSalt {
858
+ salt: string;
859
+ resolvedSeed: ResolvedBuildSeed;
860
+ engine: SaltEngine;
861
+ }
862
+ interface PrepareHashSaltInput {
863
+ seed: SeedOption;
864
+ root: string;
865
+ leg: string;
866
+ localEngineVersion: string | null;
867
+ settings: unknown;
868
+ env?: Record<string, string | undefined>;
869
+ warn?: (message: string) => void;
870
+ fetchImpl?: typeof fetch;
871
+ }
872
+ declare function prepareHashSalt(input: PrepareHashSaltInput): Promise<PreparedHashSalt>;
873
+ declare function readEngineVersion(engine: {
874
+ version?(): Promise<string>;
875
+ }): Promise<string | null>;
876
+ //#endregion
877
+ //#region src/hashed-names.d.ts
878
+ type HashTokenOf = (relativePath: string) => string | null;
879
+ interface HashedNamesOptions {
880
+ root: string;
881
+ tokenOf: HashTokenOf;
882
+ skip?: (relativePath: string) => boolean;
883
+ }
884
+ //#endregion
797
885
  //#region src/directives.d.ts
798
886
  interface CapturedDirective {
799
887
  keyword: string;
@@ -828,8 +916,30 @@ interface CapturedModule {
828
916
  srcIndex?: number;
829
917
  }
830
918
  //#endregion
919
+ //#region src/home.d.ts
920
+ declare const AFTERPACK_DIR = ".afterpack";
921
+ declare const DIAG_AFTERPACK_DIR_IN_OUTPUT = "DIAG_AFTERPACK_DIR_IN_OUTPUT";
922
+ declare const DIAG_RECEIPT_UNWRITABLE = "DIAG_RECEIPT_UNWRITABLE";
923
+ declare class AfterpackFilesError extends Error {
924
+ readonly code: string;
925
+ readonly summary: string;
926
+ readonly fix: string;
927
+ constructor(code: string, summary: string, fix: string);
928
+ }
929
+ interface AfterpackHome {
930
+ dir: string;
931
+ projectRoot: string;
932
+ marker: string | null;
933
+ strong: boolean;
934
+ buildDir: string;
935
+ }
936
+ interface AfterpackHomeOptions {
937
+ fileTarget?: boolean;
938
+ }
939
+ declare function afterpackHome(buildDir: string, options?: AfterpackHomeOptions): AfterpackHome;
940
+ //#endregion
831
941
  //#region src/receipt.d.ts
832
- declare const PROTECTION_RECEIPT_FILE = ".afterpack-protection.json";
942
+ declare const PROTECTION_RECEIPTS_DIR = "receipts";
833
943
  interface ProtectionReceiptFile {
834
944
  path: string;
835
945
  sha256: string;
@@ -845,11 +955,16 @@ interface ProtectionReceipt {
845
955
  seedOrigin: string;
846
956
  bundler: string;
847
957
  buildId: string | null;
958
+ buildDir: string;
848
959
  files: ProtectionReceiptFile[];
849
960
  }
850
961
  declare function sha256Of(path: string): string;
962
+ type HomeTarget = string | AfterpackHome;
963
+ declare function protectionReceiptPath(target: HomeTarget): string;
964
+ declare function sweepOutputTree(buildDir: string, walkedDir: string | null, label: string, ownHome?: AfterpackHome | null): void;
851
965
  interface WriteProtectionReceiptInput {
852
966
  dir: string;
967
+ home?: AfterpackHome;
853
968
  tool: string;
854
969
  engine: EngineSource | null;
855
970
  engineVersion: string | null;
@@ -859,6 +974,7 @@ interface WriteProtectionReceiptInput {
859
974
  buildId: string | null;
860
975
  files: string[];
861
976
  transformed: readonly string[];
977
+ merge?: boolean;
862
978
  }
863
979
  declare function writeDeferredProtectionReceipt(deferred: WriteProtectionReceiptInput): string | null;
864
980
  declare function writeProtectionReceipt(input: WriteProtectionReceiptInput): string;
@@ -874,12 +990,16 @@ declare class UnreadableReceiptError extends Error {
874
990
  readonly schema: number;
875
991
  constructor(message: string, receiptPath: string, schema: number);
876
992
  }
877
- declare function verifyProtectionReceipt(dir: string, expectedBuildId?: string | null): ProtectionVerification;
878
- //#endregion
879
- //#region src/seed.d.ts
880
- type SeedOption = number | string | undefined;
881
- declare const SEED_ENV_VAR = "AFTERPACK_SEED";
882
- type SeedOrigin = "option" | "git" | "env" | "session" | "fresh";
993
+ declare function verifyProtectionReceipt(receiptPath: string, dir: string, expectedBuildId?: string | null): ProtectionVerification;
994
+ interface LocatedReceipt {
995
+ receiptPath: string;
996
+ dir: string;
997
+ copiedFrom: string | null;
998
+ }
999
+ interface LocateReceiptOptions {
1000
+ copies?: boolean;
1001
+ }
1002
+ declare function locateProtectionReceipt(dir: string, options?: LocateReceiptOptions): LocatedReceipt | null;
883
1003
  //#endregion
884
1004
  //#region src/summary.d.ts
885
1005
  type PassSummaryStyle = "cli" | "plugin";
@@ -983,7 +1103,8 @@ interface ObfuscationEngine {
983
1103
  }
984
1104
  interface CombinedProtectionMapTarget {
985
1105
  buildDir: string;
986
- afterpackDir?: string;
1106
+ fileTarget?: boolean;
1107
+ subdir?: string;
987
1108
  fileName?: string;
988
1109
  }
989
1110
  interface InMemoryInput {
@@ -1027,7 +1148,12 @@ interface ObfuscationPassOptions {
1027
1148
  env?: EnvLike;
1028
1149
  messages?: PassMessages;
1029
1150
  receipt?: PassReceiptIdentity;
1030
- afterWrite?: () => void;
1151
+ afterWrite?: (writtenFiles: string[]) => void;
1152
+ resolvedSeed?: ResolvedBuildSeed;
1153
+ hashedNames?: HashedNamesOptions;
1154
+ cloudEngineExpectation?: SaltEngine;
1155
+ sourceMapSweepDir?: string | null;
1156
+ outputSweep?: boolean;
1031
1157
  diagnostics?: DiagnosticsVerbosity;
1032
1158
  telemetry?: TelemetryReporter;
1033
1159
  clientVersion?: string;
@@ -1036,6 +1162,7 @@ interface ObfuscationPassOptions {
1036
1162
  startedAt?: number;
1037
1163
  summaryStyle?: PassSummaryStyle;
1038
1164
  colorGlyph?: (glyph: string) => string;
1165
+ onBatch?: (inputs: readonly EngineFileInput[], batch: EngineBatchResult) => void;
1039
1166
  }
1040
1167
  interface PassTiming {
1041
1168
  totalMs: number;
@@ -1057,6 +1184,8 @@ interface ObfuscationPassResult {
1057
1184
  timing: PassTiming;
1058
1185
  diagnostics: DiagnosticsSummary;
1059
1186
  transformedFiles: string[];
1187
+ renamed: Map<string, string>;
1188
+ hashSalt: string | null;
1060
1189
  outputs?: InMemoryOutput[];
1061
1190
  }
1062
1191
  declare function runObfuscationPass(options: ObfuscationPassOptions): Promise<ObfuscationPassResult>;
@@ -1081,6 +1210,11 @@ interface BundleJs {
1081
1210
  }
1082
1211
  declare function collectBundleJs(bundle: OutputBundleLike, outDir: string): BundleJs;
1083
1212
  declare function sourceTypeForBundle(format: string | null | undefined, entries: Iterable<BundleEntryLike>): SourceType | undefined;
1213
+ declare function regenerateCompressedSiblings(bundle: OutputBundleLike, obfuscated: ReadonlySet<string>, label: string): void;
1214
+ declare function sriPluginRefusal(plugins: readonly {
1215
+ name?: string;
1216
+ }[] | undefined, label: string): string | null;
1217
+ declare function unsaltedAssetsWarning(entries: ReadonlyMap<string, BundleEntryLike>, salted: ReadonlySet<string>): string | null;
1084
1218
  declare function applyBundleOutput(bundle: OutputBundleLike, entry: BundleEntryLike, out: InMemoryOutput, policy: ReportPolicy): void;
1085
1219
  declare function stripBundleCssSourceMaps(bundle: OutputBundleLike): void;
1086
1220
  //#endregion
@@ -1117,42 +1251,13 @@ interface EnvParseResult {
1117
1251
  }
1118
1252
  declare function parseEnvOptions(env: Record<string, string | undefined>): EnvParseResult;
1119
1253
  //#endregion
1120
- //#region src/plugin-config.d.ts
1121
- declare const PLUGIN_LOCAL_KEYS: readonly ["git"];
1122
- type AfterpackPluginOptions = Omit<AfterpackConfig, "key"> & Pick<AfterpackArtifactOptions, (typeof PLUGIN_LOCAL_KEYS)[number]>;
1123
- interface NormalizedPluginOptions {
1124
- config: Record<string, unknown>;
1125
- issues: ConfigIssue[];
1126
- }
1127
- declare function normalizePluginOptions(input: unknown, localKeys: readonly string[], surface: string): NormalizedPluginOptions;
1128
- interface PluginConfigInput {
1129
- label: string;
1130
- options?: unknown;
1131
- argv?: string[];
1132
- cwd?: string;
1133
- env?: Record<string, string | undefined>;
1134
- localKeys?: readonly string[];
1135
- unsupported?: Readonly<Record<string, string>>;
1136
- }
1137
- interface ResolvedPluginConfig {
1138
- config: AfterpackConfig;
1139
- options: PluginOptionsView;
1140
- engineConfig: CoreConfigSubset;
1141
- configFile: string | null;
1142
- positionals: string[];
1143
- help: boolean;
1144
- version: boolean;
1145
- }
1146
- type PassSettings = Pick<ObfuscationPassOptions, "artifactOptions" | "seed" | "preset" | "complexity" | "regions" | "engineConfig" | "diagnostics" | "directivesEnabled" | "directivesEnabledExplicit">;
1147
- declare function passSettings(resolved: Pick<ResolvedPluginConfig, "options" | "engineConfig">): PassSettings;
1148
- declare function applyResolvedKey(config: AfterpackConfig, env?: Record<string, string | undefined>): void;
1149
- declare function resolvePluginConfig(input: PluginConfigInput): ResolvedPluginConfig;
1150
- //#endregion
1151
1254
  //#region src/source-map.d.ts
1152
1255
  declare function withSourceMappingURL(code: string, url: string | null): string;
1153
1256
  declare function withoutCssSourceMappingURL(css: string): string;
1154
1257
  declare function extractSourceMappingURL(code: string): string | null;
1155
1258
  declare function decodeDataUri(url: string): string | null;
1156
1259
  declare function discoverInputSourceMap(jsPath: string, code?: string): string | null;
1260
+ declare function removeSourceMaps(paths: Iterable<string>, label: string): number;
1261
+ declare function stripCssSourceMappingURLs(paths: Iterable<string>): number;
1157
1262
  //#endregion
1158
- 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 SourceType, 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, sourceTypeForBundle, sourceTypeForOutputFormat, stripBundleCssSourceMaps, toEngineConfig, toPluginOptions, validateConfig, verifyProtectionReceipt, withSourceMappingURL, withoutCssSourceMappingURL, writeArtifacts, writeDeferredProtectionReceipt, writeProtectionReceipt };
1263
+ export { AFTERPACK_DIR, type AfterpackArtifactOptions, type AfterpackConfig, AfterpackFilesError, type AfterpackHome, type AfterpackHomeOptions, 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_AFTERPACK_DIR_IN_OUTPUT, DIAG_ALREADY_OBFUSCATED, DIAG_RECEIPT_UNREADABLE, DIAG_RECEIPT_UNWRITABLE, 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 HashTokenOf, type HashedNamesOptions, type HomeTarget, type InMemoryInput, type InMemoryOutput, type LoadedConfigFile, type LocateReceiptOptions, type LocatedReceipt, type Logger, type NormalizedPluginOptions, type NoticeLogger, type NoticeSeverity, type ObfuscationEngine, type ObfuscationPassOptions, type ObfuscationPassResult, type OutputBundleLike, PROTECTION_RECEIPTS_DIR, type PassMessages, type PassReceiptIdentity, type PassSettings, type PassTiming, type PluginConfigInput, type PluginOptionsView, type PrepareHashSaltInput, type PreparedHashSalt, type Preset, type ProtectionReceipt, type ProtectionReceiptFile, type ProtectionVerification, type RegionConfig, type ReportPolicy, type ReportPolicySignals, type ResolvedBuildSeed, type ResolvedPluginConfig, SEED_ENV_VAR, type SafeNotice, type SaltEngine, type SeedOption, type SeedOrigin, type SourceType, 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, afterpackHome, applyBundleOutput, applyResolvedKey, collectBundleJs, collectJsFiles, collectSourceMaps, collectStylesheets, createTelemetryReporter, decodeDataUri, discoverInputSourceMap, ensureAfterpackGitignore, extractSourceMappingURL, findUpward, getPath, installedRequiredLine, loadConfigFile, locateProtectionReceipt, mergeConfig, normalizePluginOptions, npxAlternative, parseCliOptions, parseEnvOptions, passSettings, prepareHashSalt, protectionReceiptPath, readEngineVersion, regenerateCompressedSiblings, removeSourceMaps, reportPolicySaltBits, resolveClientIdentity, resolvePluginConfig, resolveReportPolicy, runObfuscationPass, saltSettings, sanitizeNotices, scanDirectives, serverAddsInfo, sha256Of, sourceTypeForBundle, sourceTypeForOutputFormat, sriPluginRefusal, stripBundleCssSourceMaps, stripCssSourceMappingURLs, sweepOutputTree, toEngineConfig, toPluginOptions, unsaltedAssetsWarning, validateConfig, verifyProtectionReceipt, withSourceMappingURL, withoutCssSourceMappingURL, writeArtifacts, writeDeferredProtectionReceipt, writeProtectionReceipt };
package/dist/index.d.ts CHANGED
@@ -244,7 +244,7 @@ declare const CONFIG_KEYS: readonly [{
244
244
  readonly item: {
245
245
  readonly kind: "boolean";
246
246
  };
247
- readonly default: "true in development when an input map exists; false in production";
247
+ readonly default: "false; true in development mode when an input map exists";
248
248
  }, {
249
249
  readonly path: "sourceMap.sourcesContent";
250
250
  readonly shape: "scalar";
@@ -254,7 +254,7 @@ declare const CONFIG_KEYS: readonly [{
254
254
  readonly item: {
255
255
  readonly kind: "boolean";
256
256
  };
257
- readonly default: "true in development; false in production";
257
+ readonly default: "false; true in development mode";
258
258
  }, {
259
259
  readonly path: "sourceMap.emitUrl";
260
260
  readonly shape: "scalar";
@@ -264,7 +264,7 @@ declare const CONFIG_KEYS: readonly [{
264
264
  readonly item: {
265
265
  readonly kind: "boolean";
266
266
  };
267
- readonly default: "true in development; false in production";
267
+ readonly default: "false; true in development mode";
268
268
  }, {
269
269
  readonly path: "protectionMap.enabled";
270
270
  readonly shape: "scalar";
@@ -416,7 +416,7 @@ declare const CONFIG_KEYS: readonly [{
416
416
  readonly kind: "enum";
417
417
  readonly values: readonly ["production", "development"];
418
418
  };
419
- readonly default: "detected from the environment";
419
+ readonly default: "production, unless NODE_ENV is development";
420
420
  }, {
421
421
  readonly path: "directives.enabled";
422
422
  readonly shape: "scalar";
@@ -682,7 +682,7 @@ interface WriteArtifactsInput {
682
682
  originalSource: string | null;
683
683
  policy: ReportPolicy;
684
684
  mode?: ArtifactMode;
685
- afterpackDir?: string;
685
+ afterpackDir: string;
686
686
  logger?: Logger;
687
687
  }
688
688
  interface WriteArtifactsResult {
@@ -794,6 +794,94 @@ declare class AlreadyObfuscatedError extends Error {
794
794
  constructor(message: string, files: readonly string[], receiptPath: string, dir: string);
795
795
  }
796
796
  //#endregion
797
+ //#region src/plugin-config.d.ts
798
+ declare const PLUGIN_LOCAL_KEYS: readonly ["git"];
799
+ type AfterpackPluginOptions = Omit<AfterpackConfig, "key"> & Pick<AfterpackArtifactOptions, (typeof PLUGIN_LOCAL_KEYS)[number]>;
800
+ interface NormalizedPluginOptions {
801
+ config: Record<string, unknown>;
802
+ issues: ConfigIssue[];
803
+ }
804
+ declare function normalizePluginOptions(input: unknown, localKeys: readonly string[], surface: string): NormalizedPluginOptions;
805
+ interface PluginConfigInput {
806
+ label: string;
807
+ options?: unknown;
808
+ argv?: string[];
809
+ cwd?: string;
810
+ env?: Record<string, string | undefined>;
811
+ localKeys?: readonly string[];
812
+ unsupported?: Readonly<Record<string, string>>;
813
+ }
814
+ interface ResolvedPluginConfig {
815
+ config: AfterpackConfig;
816
+ options: PluginOptionsView;
817
+ engineConfig: CoreConfigSubset;
818
+ configFile: string | null;
819
+ positionals: string[];
820
+ help: boolean;
821
+ version: boolean;
822
+ }
823
+ type PassSettings = Pick<ObfuscationPassOptions, "artifactOptions" | "seed" | "preset" | "complexity" | "regions" | "engineConfig" | "diagnostics" | "directivesEnabled" | "directivesEnabledExplicit">;
824
+ declare function passSettings(resolved: Pick<ResolvedPluginConfig, "options" | "engineConfig">): PassSettings;
825
+ declare function applyResolvedKey(config: AfterpackConfig, env?: Record<string, string | undefined>): void;
826
+ declare function resolvePluginConfig(input: PluginConfigInput): ResolvedPluginConfig;
827
+ //#endregion
828
+ //#region src/seed.d.ts
829
+ type SeedOption = number | string | undefined;
830
+ declare const SEED_ENV_VAR = "AFTERPACK_SEED";
831
+ type SeedOrigin = "option" | "git" | "env" | "session" | "fresh";
832
+ interface ResolvedBuildSeed {
833
+ seed: number | string;
834
+ origin: SeedOrigin;
835
+ legs: string[];
836
+ generation: number;
837
+ mismatch: {
838
+ leg: string;
839
+ seed: number | string;
840
+ } | null;
841
+ }
842
+ //#endregion
843
+ //#region src/hash-salt.d.ts
844
+ interface SaltEngine {
845
+ engineVersion: string | null;
846
+ nonce: string | null;
847
+ cloud: boolean;
848
+ probedCloudVersion: string | null;
849
+ probeFailed: boolean;
850
+ }
851
+ declare function saltSettings(settings: PassSettings, extra?: Record<string, unknown>): unknown;
852
+ interface ReportPolicySaltBits {
853
+ sourceMap: boolean;
854
+ emitSourceMappingURL: boolean;
855
+ }
856
+ declare function reportPolicySaltBits(env: Record<string, string | undefined>, artifactOptions: PassSettings["artifactOptions"], hasBundlerSourcemap: boolean): ReportPolicySaltBits;
857
+ interface PreparedHashSalt {
858
+ salt: string;
859
+ resolvedSeed: ResolvedBuildSeed;
860
+ engine: SaltEngine;
861
+ }
862
+ interface PrepareHashSaltInput {
863
+ seed: SeedOption;
864
+ root: string;
865
+ leg: string;
866
+ localEngineVersion: string | null;
867
+ settings: unknown;
868
+ env?: Record<string, string | undefined>;
869
+ warn?: (message: string) => void;
870
+ fetchImpl?: typeof fetch;
871
+ }
872
+ declare function prepareHashSalt(input: PrepareHashSaltInput): Promise<PreparedHashSalt>;
873
+ declare function readEngineVersion(engine: {
874
+ version?(): Promise<string>;
875
+ }): Promise<string | null>;
876
+ //#endregion
877
+ //#region src/hashed-names.d.ts
878
+ type HashTokenOf = (relativePath: string) => string | null;
879
+ interface HashedNamesOptions {
880
+ root: string;
881
+ tokenOf: HashTokenOf;
882
+ skip?: (relativePath: string) => boolean;
883
+ }
884
+ //#endregion
797
885
  //#region src/directives.d.ts
798
886
  interface CapturedDirective {
799
887
  keyword: string;
@@ -828,8 +916,30 @@ interface CapturedModule {
828
916
  srcIndex?: number;
829
917
  }
830
918
  //#endregion
919
+ //#region src/home.d.ts
920
+ declare const AFTERPACK_DIR = ".afterpack";
921
+ declare const DIAG_AFTERPACK_DIR_IN_OUTPUT = "DIAG_AFTERPACK_DIR_IN_OUTPUT";
922
+ declare const DIAG_RECEIPT_UNWRITABLE = "DIAG_RECEIPT_UNWRITABLE";
923
+ declare class AfterpackFilesError extends Error {
924
+ readonly code: string;
925
+ readonly summary: string;
926
+ readonly fix: string;
927
+ constructor(code: string, summary: string, fix: string);
928
+ }
929
+ interface AfterpackHome {
930
+ dir: string;
931
+ projectRoot: string;
932
+ marker: string | null;
933
+ strong: boolean;
934
+ buildDir: string;
935
+ }
936
+ interface AfterpackHomeOptions {
937
+ fileTarget?: boolean;
938
+ }
939
+ declare function afterpackHome(buildDir: string, options?: AfterpackHomeOptions): AfterpackHome;
940
+ //#endregion
831
941
  //#region src/receipt.d.ts
832
- declare const PROTECTION_RECEIPT_FILE = ".afterpack-protection.json";
942
+ declare const PROTECTION_RECEIPTS_DIR = "receipts";
833
943
  interface ProtectionReceiptFile {
834
944
  path: string;
835
945
  sha256: string;
@@ -845,11 +955,16 @@ interface ProtectionReceipt {
845
955
  seedOrigin: string;
846
956
  bundler: string;
847
957
  buildId: string | null;
958
+ buildDir: string;
848
959
  files: ProtectionReceiptFile[];
849
960
  }
850
961
  declare function sha256Of(path: string): string;
962
+ type HomeTarget = string | AfterpackHome;
963
+ declare function protectionReceiptPath(target: HomeTarget): string;
964
+ declare function sweepOutputTree(buildDir: string, walkedDir: string | null, label: string, ownHome?: AfterpackHome | null): void;
851
965
  interface WriteProtectionReceiptInput {
852
966
  dir: string;
967
+ home?: AfterpackHome;
853
968
  tool: string;
854
969
  engine: EngineSource | null;
855
970
  engineVersion: string | null;
@@ -859,6 +974,7 @@ interface WriteProtectionReceiptInput {
859
974
  buildId: string | null;
860
975
  files: string[];
861
976
  transformed: readonly string[];
977
+ merge?: boolean;
862
978
  }
863
979
  declare function writeDeferredProtectionReceipt(deferred: WriteProtectionReceiptInput): string | null;
864
980
  declare function writeProtectionReceipt(input: WriteProtectionReceiptInput): string;
@@ -874,12 +990,16 @@ declare class UnreadableReceiptError extends Error {
874
990
  readonly schema: number;
875
991
  constructor(message: string, receiptPath: string, schema: number);
876
992
  }
877
- declare function verifyProtectionReceipt(dir: string, expectedBuildId?: string | null): ProtectionVerification;
878
- //#endregion
879
- //#region src/seed.d.ts
880
- type SeedOption = number | string | undefined;
881
- declare const SEED_ENV_VAR = "AFTERPACK_SEED";
882
- type SeedOrigin = "option" | "git" | "env" | "session" | "fresh";
993
+ declare function verifyProtectionReceipt(receiptPath: string, dir: string, expectedBuildId?: string | null): ProtectionVerification;
994
+ interface LocatedReceipt {
995
+ receiptPath: string;
996
+ dir: string;
997
+ copiedFrom: string | null;
998
+ }
999
+ interface LocateReceiptOptions {
1000
+ copies?: boolean;
1001
+ }
1002
+ declare function locateProtectionReceipt(dir: string, options?: LocateReceiptOptions): LocatedReceipt | null;
883
1003
  //#endregion
884
1004
  //#region src/summary.d.ts
885
1005
  type PassSummaryStyle = "cli" | "plugin";
@@ -983,7 +1103,8 @@ interface ObfuscationEngine {
983
1103
  }
984
1104
  interface CombinedProtectionMapTarget {
985
1105
  buildDir: string;
986
- afterpackDir?: string;
1106
+ fileTarget?: boolean;
1107
+ subdir?: string;
987
1108
  fileName?: string;
988
1109
  }
989
1110
  interface InMemoryInput {
@@ -1027,7 +1148,12 @@ interface ObfuscationPassOptions {
1027
1148
  env?: EnvLike;
1028
1149
  messages?: PassMessages;
1029
1150
  receipt?: PassReceiptIdentity;
1030
- afterWrite?: () => void;
1151
+ afterWrite?: (writtenFiles: string[]) => void;
1152
+ resolvedSeed?: ResolvedBuildSeed;
1153
+ hashedNames?: HashedNamesOptions;
1154
+ cloudEngineExpectation?: SaltEngine;
1155
+ sourceMapSweepDir?: string | null;
1156
+ outputSweep?: boolean;
1031
1157
  diagnostics?: DiagnosticsVerbosity;
1032
1158
  telemetry?: TelemetryReporter;
1033
1159
  clientVersion?: string;
@@ -1036,6 +1162,7 @@ interface ObfuscationPassOptions {
1036
1162
  startedAt?: number;
1037
1163
  summaryStyle?: PassSummaryStyle;
1038
1164
  colorGlyph?: (glyph: string) => string;
1165
+ onBatch?: (inputs: readonly EngineFileInput[], batch: EngineBatchResult) => void;
1039
1166
  }
1040
1167
  interface PassTiming {
1041
1168
  totalMs: number;
@@ -1057,6 +1184,8 @@ interface ObfuscationPassResult {
1057
1184
  timing: PassTiming;
1058
1185
  diagnostics: DiagnosticsSummary;
1059
1186
  transformedFiles: string[];
1187
+ renamed: Map<string, string>;
1188
+ hashSalt: string | null;
1060
1189
  outputs?: InMemoryOutput[];
1061
1190
  }
1062
1191
  declare function runObfuscationPass(options: ObfuscationPassOptions): Promise<ObfuscationPassResult>;
@@ -1081,6 +1210,11 @@ interface BundleJs {
1081
1210
  }
1082
1211
  declare function collectBundleJs(bundle: OutputBundleLike, outDir: string): BundleJs;
1083
1212
  declare function sourceTypeForBundle(format: string | null | undefined, entries: Iterable<BundleEntryLike>): SourceType | undefined;
1213
+ declare function regenerateCompressedSiblings(bundle: OutputBundleLike, obfuscated: ReadonlySet<string>, label: string): void;
1214
+ declare function sriPluginRefusal(plugins: readonly {
1215
+ name?: string;
1216
+ }[] | undefined, label: string): string | null;
1217
+ declare function unsaltedAssetsWarning(entries: ReadonlyMap<string, BundleEntryLike>, salted: ReadonlySet<string>): string | null;
1084
1218
  declare function applyBundleOutput(bundle: OutputBundleLike, entry: BundleEntryLike, out: InMemoryOutput, policy: ReportPolicy): void;
1085
1219
  declare function stripBundleCssSourceMaps(bundle: OutputBundleLike): void;
1086
1220
  //#endregion
@@ -1117,42 +1251,13 @@ interface EnvParseResult {
1117
1251
  }
1118
1252
  declare function parseEnvOptions(env: Record<string, string | undefined>): EnvParseResult;
1119
1253
  //#endregion
1120
- //#region src/plugin-config.d.ts
1121
- declare const PLUGIN_LOCAL_KEYS: readonly ["git"];
1122
- type AfterpackPluginOptions = Omit<AfterpackConfig, "key"> & Pick<AfterpackArtifactOptions, (typeof PLUGIN_LOCAL_KEYS)[number]>;
1123
- interface NormalizedPluginOptions {
1124
- config: Record<string, unknown>;
1125
- issues: ConfigIssue[];
1126
- }
1127
- declare function normalizePluginOptions(input: unknown, localKeys: readonly string[], surface: string): NormalizedPluginOptions;
1128
- interface PluginConfigInput {
1129
- label: string;
1130
- options?: unknown;
1131
- argv?: string[];
1132
- cwd?: string;
1133
- env?: Record<string, string | undefined>;
1134
- localKeys?: readonly string[];
1135
- unsupported?: Readonly<Record<string, string>>;
1136
- }
1137
- interface ResolvedPluginConfig {
1138
- config: AfterpackConfig;
1139
- options: PluginOptionsView;
1140
- engineConfig: CoreConfigSubset;
1141
- configFile: string | null;
1142
- positionals: string[];
1143
- help: boolean;
1144
- version: boolean;
1145
- }
1146
- type PassSettings = Pick<ObfuscationPassOptions, "artifactOptions" | "seed" | "preset" | "complexity" | "regions" | "engineConfig" | "diagnostics" | "directivesEnabled" | "directivesEnabledExplicit">;
1147
- declare function passSettings(resolved: Pick<ResolvedPluginConfig, "options" | "engineConfig">): PassSettings;
1148
- declare function applyResolvedKey(config: AfterpackConfig, env?: Record<string, string | undefined>): void;
1149
- declare function resolvePluginConfig(input: PluginConfigInput): ResolvedPluginConfig;
1150
- //#endregion
1151
1254
  //#region src/source-map.d.ts
1152
1255
  declare function withSourceMappingURL(code: string, url: string | null): string;
1153
1256
  declare function withoutCssSourceMappingURL(css: string): string;
1154
1257
  declare function extractSourceMappingURL(code: string): string | null;
1155
1258
  declare function decodeDataUri(url: string): string | null;
1156
1259
  declare function discoverInputSourceMap(jsPath: string, code?: string): string | null;
1260
+ declare function removeSourceMaps(paths: Iterable<string>, label: string): number;
1261
+ declare function stripCssSourceMappingURLs(paths: Iterable<string>): number;
1157
1262
  //#endregion
1158
- 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 SourceType, 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, sourceTypeForBundle, sourceTypeForOutputFormat, stripBundleCssSourceMaps, toEngineConfig, toPluginOptions, validateConfig, verifyProtectionReceipt, withSourceMappingURL, withoutCssSourceMappingURL, writeArtifacts, writeDeferredProtectionReceipt, writeProtectionReceipt };
1263
+ export { AFTERPACK_DIR, type AfterpackArtifactOptions, type AfterpackConfig, AfterpackFilesError, type AfterpackHome, type AfterpackHomeOptions, 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_AFTERPACK_DIR_IN_OUTPUT, DIAG_ALREADY_OBFUSCATED, DIAG_RECEIPT_UNREADABLE, DIAG_RECEIPT_UNWRITABLE, 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 HashTokenOf, type HashedNamesOptions, type HomeTarget, type InMemoryInput, type InMemoryOutput, type LoadedConfigFile, type LocateReceiptOptions, type LocatedReceipt, type Logger, type NormalizedPluginOptions, type NoticeLogger, type NoticeSeverity, type ObfuscationEngine, type ObfuscationPassOptions, type ObfuscationPassResult, type OutputBundleLike, PROTECTION_RECEIPTS_DIR, type PassMessages, type PassReceiptIdentity, type PassSettings, type PassTiming, type PluginConfigInput, type PluginOptionsView, type PrepareHashSaltInput, type PreparedHashSalt, type Preset, type ProtectionReceipt, type ProtectionReceiptFile, type ProtectionVerification, type RegionConfig, type ReportPolicy, type ReportPolicySignals, type ResolvedBuildSeed, type ResolvedPluginConfig, SEED_ENV_VAR, type SafeNotice, type SaltEngine, type SeedOption, type SeedOrigin, type SourceType, 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, afterpackHome, applyBundleOutput, applyResolvedKey, collectBundleJs, collectJsFiles, collectSourceMaps, collectStylesheets, createTelemetryReporter, decodeDataUri, discoverInputSourceMap, ensureAfterpackGitignore, extractSourceMappingURL, findUpward, getPath, installedRequiredLine, loadConfigFile, locateProtectionReceipt, mergeConfig, normalizePluginOptions, npxAlternative, parseCliOptions, parseEnvOptions, passSettings, prepareHashSalt, protectionReceiptPath, readEngineVersion, regenerateCompressedSiblings, removeSourceMaps, reportPolicySaltBits, resolveClientIdentity, resolvePluginConfig, resolveReportPolicy, runObfuscationPass, saltSettings, sanitizeNotices, scanDirectives, serverAddsInfo, sha256Of, sourceTypeForBundle, sourceTypeForOutputFormat, sriPluginRefusal, stripBundleCssSourceMaps, stripCssSourceMappingURLs, sweepOutputTree, toEngineConfig, toPluginOptions, unsaltedAssetsWarning, validateConfig, verifyProtectionReceipt, withSourceMappingURL, withoutCssSourceMappingURL, writeArtifacts, writeDeferredProtectionReceipt, writeProtectionReceipt };