@byaga/cdk-patterns 0.9.3 → 0.11.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 (117) hide show
  1. package/.fleet/run.json +11 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +43 -0
  4. package/archive/ApiAttachPoint.ts +9 -0
  5. package/archive/ApiCertificate.ts +32 -0
  6. package/{lib/CognitoApiGatewayAuthorizer.d.ts → archive/CognitoApiGatewayAuthorizer.ts} +13 -7
  7. package/archive/DynamoDbTable.ts +40 -0
  8. package/archive/ICorsConfig.ts +5 -0
  9. package/archive/IDomainConfig.ts +8 -0
  10. package/archive/IHostedZoneConfig.ts +5 -0
  11. package/archive/NodeJsLambdaLayer.ts +42 -0
  12. package/archive/Output.ts +11 -0
  13. package/{lib/RestApi.js → archive/RestApi.ts} +96 -60
  14. package/{lib/Role.d.ts → archive/Role.ts} +165 -139
  15. package/archive/StaticWebSite.ts +159 -0
  16. package/archive/index.ts +18 -0
  17. package/archive/methods/apply-schema-to-method-options.ts +38 -0
  18. package/archive/methods/attach-function-to-api.ts +69 -0
  19. package/lib/build/copy-files.d.ts +8 -0
  20. package/lib/{methods/empty-directory.js → build/copy-files.js} +22 -15
  21. package/lib/build/generate-hash.d.ts +7 -0
  22. package/lib/build/generate-hash.js +31 -0
  23. package/lib/build/get-files.d.ts +9 -0
  24. package/lib/build/get-files.js +38 -0
  25. package/lib/build/get-source-directory.d.ts +18 -0
  26. package/lib/build/get-source-directory.js +38 -0
  27. package/lib/build/hash-file.d.ts +18 -0
  28. package/lib/build/hash-file.js +45 -0
  29. package/lib/build/nodejs/build-ecmascript.d.ts +9 -0
  30. package/lib/build/nodejs/build-ecmascript.js +20 -0
  31. package/lib/build/nodejs/build-node-source.d.ts +12 -0
  32. package/lib/build/nodejs/build-node-source.js +39 -0
  33. package/lib/build/nodejs/build-typescript.d.ts +8 -0
  34. package/lib/build/nodejs/build-typescript.js +33 -0
  35. package/lib/build/nodejs/install-node-modules.d.ts +12 -0
  36. package/lib/build/nodejs/install-node-modules.js +30 -0
  37. package/lib/create-stack.d.ts +38 -0
  38. package/lib/create-stack.js +46 -0
  39. package/lib/generate-identifier.d.ts +27 -0
  40. package/lib/generate-identifier.js +65 -0
  41. package/lib/index.d.ts +7 -15
  42. package/lib/index.js +40 -25
  43. package/lib/lambda/create-function.d.ts +20 -0
  44. package/lib/lambda/create-function.js +39 -0
  45. package/lib/lambda/create-nodejs-lambda.d.ts +28 -0
  46. package/lib/lambda/create-nodejs-lambda.js +38 -0
  47. package/lib/lambda-layer/apply-honeycomb-to-lambda.d.ts +2 -0
  48. package/lib/lambda-layer/apply-honeycomb-to-lambda.js +25 -0
  49. package/lib/lambda-layer/get-layer.d.ts +2 -0
  50. package/lib/lambda-layer/get-layer.js +20 -0
  51. package/lib/lambda-layer/layer-cache.d.ts +3 -0
  52. package/lib/lambda-layer/layer-cache.js +12 -0
  53. package/lib/ssm/SsmParameter.d.ts +12 -0
  54. package/lib/ssm/get-existing-parameter.d.ts +9 -0
  55. package/lib/ssm/get-existing-parameter.js +41 -0
  56. package/lib/ssm/grant-read.d.ts +7 -0
  57. package/lib/ssm/grant-read.js +24 -0
  58. package/lib/ssm/index.d.ts +3 -0
  59. package/lib/ssm/index.js +9 -0
  60. package/lib/ssm/parameter-cache.d.ts +13 -0
  61. package/lib/ssm/parameter-cache.js +23 -0
  62. package/lib/ssm/string-value.d.ts +8 -0
  63. package/lib/ssm/string-value.js +14 -0
  64. package/lib/tools/duration.d.ts +10 -0
  65. package/lib/tools/duration.js +28 -0
  66. package/package.json +25 -11
  67. package/jest.config.js +0 -16
  68. package/lib/ApiCertificate.d.ts +0 -10
  69. package/lib/ApiCertificate.js +0 -31
  70. package/lib/CognitoApiGatewayAuthorizer.js +0 -24
  71. package/lib/DeployStack.d.ts +0 -23
  72. package/lib/DeployStack.js +0 -58
  73. package/lib/DynamoDbTable.d.ts +0 -12
  74. package/lib/DynamoDbTable.js +0 -34
  75. package/lib/FunctionIntegration.d.ts +0 -25
  76. package/lib/FunctionIntegration.js +0 -65
  77. package/lib/ICorsConfig.d.ts +0 -5
  78. package/lib/IDeployStack.d.ts +0 -20
  79. package/lib/IDeployStack.js +0 -48
  80. package/lib/IDomainConfig.d.ts +0 -7
  81. package/lib/IDomainConfig.js +0 -2
  82. package/lib/IHostedZoneConfig.d.ts +0 -5
  83. package/lib/IHostedZoneConfig.js +0 -2
  84. package/lib/IStackArguments.d.ts +0 -8
  85. package/lib/IStackArguments.js +0 -2
  86. package/lib/NodeJsLambda.d.ts +0 -13
  87. package/lib/NodeJsLambda.js +0 -28
  88. package/lib/NodeJsLambdaLayer.d.ts +0 -12
  89. package/lib/NodeJsLambdaLayer.js +0 -24
  90. package/lib/Output.d.ts +0 -5
  91. package/lib/Output.js +0 -13
  92. package/lib/RestApi.d.ts +0 -28
  93. package/lib/Role.js +0 -27
  94. package/lib/SsmParameter.d.ts +0 -18
  95. package/lib/SsmParameter.js +0 -40
  96. package/lib/StaticWebSite.d.ts +0 -17
  97. package/lib/StaticWebSite.js +0 -122
  98. package/lib/methods/apply-honeycomb-to-lambda.d.ts +0 -3
  99. package/lib/methods/apply-honeycomb-to-lambda.js +0 -23
  100. package/lib/methods/apply-honeycomb-to-lambda.spec.d.ts +0 -1
  101. package/lib/methods/apply-honeycomb-to-lambda.spec.js +0 -61
  102. package/lib/methods/build-node-source.d.ts +0 -13
  103. package/lib/methods/build-node-source.js +0 -105
  104. package/lib/methods/duration.d.ts +0 -8
  105. package/lib/methods/duration.js +0 -22
  106. package/lib/methods/empty-directory.d.ts +0 -2
  107. package/lib/methods/generate-hash.d.ts +0 -15
  108. package/lib/methods/generate-hash.js +0 -59
  109. package/lib/methods/get-source-directory.d.ts +0 -4
  110. package/lib/methods/get-source-directory.js +0 -37
  111. package/lib/methods/walk-directory.d.ts +0 -14
  112. package/lib/methods/walk-directory.js +0 -48
  113. package/test-results/html/index.html +0 -1
  114. package/test-results/html/jest-html-reporters-attach/index/index.js +0 -3
  115. package/test-results/html/jest-html-reporters-attach/index/result.js +0 -1
  116. package/test-results/junit/junit.xml +0 -13
  117. /package/lib/{ICorsConfig.js → ssm/SsmParameter.js} +0 -0
@@ -1,122 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.StaticWebSite = void 0;
7
- const core_1 = require("aws-cdk-lib/core");
8
- const Output_1 = require("./Output");
9
- const child_process_1 = require("child_process");
10
- const aws_s3_1 = require("aws-cdk-lib/aws-s3");
11
- const aws_s3_deployment_1 = require("aws-cdk-lib/aws-s3-deployment");
12
- const ApiCertificate_1 = __importDefault(require("./ApiCertificate"));
13
- const aws_cloudfront_1 = require("aws-cdk-lib/aws-cloudfront");
14
- const aws_iam_1 = require("aws-cdk-lib/aws-iam");
15
- const aws_route53_1 = require("aws-cdk-lib/aws-route53");
16
- const aws_route53_targets_1 = require("aws-cdk-lib/aws-route53-targets");
17
- const duration_1 = __importDefault(require("./methods/duration"));
18
- const build_node_source_1 = require("./methods/build-node-source");
19
- const walk_directory_1 = require("./methods/walk-directory");
20
- const aws_cdk_lib_1 = require("aws-cdk-lib");
21
- class StaticWebSite {
22
- constructor(stack, id, props) {
23
- console.log('Deploying Static Web Site', id);
24
- const done = (0, duration_1.default)();
25
- const childrenExcluded = props.ignore?.childrenExcluded || walk_directory_1.no;
26
- const { buildDir, moduleChanged } = (0, build_node_source_1.buildNodeSource)('web', id, {
27
- ignore: {
28
- ...props.ignore,
29
- childrenExcluded: stat => stat.name === 'out' || childrenExcluded(stat)
30
- }
31
- });
32
- if (moduleChanged) {
33
- console.log('Building UI Source', id);
34
- (0, child_process_1.execSync)('npm run export', {
35
- cwd: buildDir,
36
- env: props.env
37
- });
38
- }
39
- console.log('Total Build Duration (ms)', done());
40
- const exportDir = buildDir + '/out';
41
- console.log('Creating HTTPS Certificate', id + '-certificate');
42
- const certificate = new ApiCertificate_1.default(stack, id + '-certificate', props.domain);
43
- console.log('Deploying Site Content Bucket', stack.genId(id, "content-bucket"));
44
- const s3BucketSource = new aws_s3_1.Bucket(stack, stack.genId(id, "content-bucket"), {
45
- bucketName: certificate.domain,
46
- websiteIndexDocument: "index.html",
47
- websiteErrorDocument: "error.html",
48
- removalPolicy: core_1.RemovalPolicy.DESTROY,
49
- autoDeleteObjects: true
50
- });
51
- new Output_1.Output(stack, `${id}-content-bucket`, s3BucketSource.bucketName);
52
- const cloudFrontPolicy = new aws_iam_1.PolicyStatement({
53
- actions: ['s3:GetBucket*', 's3:GetObject*', 's3:List*'],
54
- resources: [s3BucketSource.bucketArn, s3BucketSource.bucketArn + '/*'],
55
- });
56
- new aws_s3_deployment_1.BucketDeployment(stack, stack.genId(id, 'bucket-deployment'), {
57
- sources: [aws_s3_deployment_1.Source.asset(exportDir)],
58
- destinationBucket: s3BucketSource
59
- });
60
- const originAccessIdentity = new aws_cloudfront_1.OriginAccessIdentity(stack, "WebsiteOAI");
61
- cloudFrontPolicy.addArnPrincipal(originAccessIdentity.cloudFrontOriginAccessIdentityS3CanonicalUserId);
62
- s3BucketSource.grantRead(originAccessIdentity);
63
- const distro = new aws_cloudfront_1.CloudFrontWebDistribution(stack, stack.genId(id, 'cloudfront-web-distribution'), {
64
- enabled: true,
65
- originConfigs: [...props.proxy || [], {
66
- s3OriginSource: {
67
- s3BucketSource,
68
- originAccessIdentity
69
- },
70
- behaviors: [{
71
- allowedMethods: aws_cloudfront_1.CloudFrontAllowedMethods.GET_HEAD_OPTIONS,
72
- isDefaultBehavior: true
73
- }]
74
- }],
75
- viewerProtocolPolicy: aws_cloudfront_1.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
76
- viewerCertificate: aws_cloudfront_1.ViewerCertificate.fromAcmCertificate(certificate, {
77
- aliases: [certificate.domain],
78
- sslMethod: aws_cloudfront_1.SSLMethod.SNI
79
- })
80
- });
81
- new Output_1.Output(stack, `${id}-base-url`, "https://" + certificate.domain);
82
- console.log('Setting Route53 A-Name Record', props.domain.domainName);
83
- new aws_route53_1.ARecord(stack, stack.genId('alias'), {
84
- zone: certificate.hostedZone,
85
- recordName: certificate.domain,
86
- target: aws_route53_1.RecordTarget.fromAlias(new aws_route53_targets_1.CloudFrontTarget(distro))
87
- });
88
- }
89
- static defineProxy(stack, domainName, pathPattern) {
90
- return {
91
- customOriginSource: {
92
- domainName: domainName,
93
- originPath: `/${stack.stage}`,
94
- originProtocolPolicy: aws_cloudfront_1.OriginProtocolPolicy.HTTPS_ONLY
95
- },
96
- behaviors: [{
97
- pathPattern,
98
- allowedMethods: aws_cloudfront_1.CloudFrontAllowedMethods.ALL,
99
- maxTtl: aws_cdk_lib_1.Duration.seconds(0),
100
- minTtl: aws_cdk_lib_1.Duration.seconds(0),
101
- defaultTtl: aws_cdk_lib_1.Duration.seconds(0),
102
- compress: false,
103
- forwardedValues: {
104
- queryString: true,
105
- headers: [
106
- "Authorization",
107
- "User-Agent",
108
- "X-Trace-Id",
109
- "X-Span-Id",
110
- "X-Correlation-Id",
111
- 'Referer',
112
- "User-Agent",
113
- "Accept-Language",
114
- 'Content-Type',
115
- 'Content-Length'
116
- ]
117
- }
118
- }]
119
- };
120
- }
121
- }
122
- exports.StaticWebSite = StaticWebSite;
@@ -1,3 +0,0 @@
1
- import { FunctionProps } from "aws-cdk-lib/aws-lambda";
2
- import { DeployStack } from "../DeployStack";
3
- export declare function applyHoneycombToLambda(stack: DeployStack, props: FunctionProps): FunctionProps;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyHoneycombToLambda = void 0;
4
- const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
5
- const SsmParameter_1 = require("../SsmParameter");
6
- let honeyCombLayer;
7
- function applyHoneycombToLambda(stack, props) {
8
- if (!honeyCombLayer)
9
- honeyCombLayer = aws_lambda_1.LayerVersion.fromLayerVersionArn(stack, stack.genId('hc-layer'), `arn:aws:lambda:${stack.region}:702835727665:layer:honeycomb-lambda-extension-x86_64-v11-1-1:1`);
10
- const layers = props.layers ? [...props.layers] : [];
11
- const environment = { ...props.environment };
12
- const options = { parameterGroup: stack.project };
13
- layers.push(honeyCombLayer);
14
- environment.LIBHONEY_API_KEY = new SsmParameter_1.SsmParameter(stack, `/honeycomb/api-key`, options).stringValue;
15
- environment.LIBHONEY_DATASET = new SsmParameter_1.SsmParameter(stack, `/honeycomb/dataset`, options).stringValue;
16
- environment.LOGS_API_DISABLE_PLATFORM_MSGS = "true";
17
- return {
18
- ...props,
19
- layers,
20
- environment
21
- };
22
- }
23
- exports.applyHoneycombToLambda = applyHoneycombToLambda;
@@ -1 +0,0 @@
1
- export {};
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const ts_mockito_1 = require("ts-mockito");
4
- const DeployStack_1 = require("../DeployStack");
5
- const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
6
- const apply_honeycomb_to_lambda_1 = require("./apply-honeycomb-to-lambda");
7
- let mockStack;
8
- let mockLayer;
9
- let fromLayerVersionArn;
10
- jest.mock('../SsmParameter', () => {
11
- const { SsmParameter } = jest.requireActual('../SsmParameter');
12
- class MockSsmParameter extends SsmParameter {
13
- static mocks = {
14
- stringValue: jest.fn()
15
- };
16
- get stringValue() {
17
- return MockSsmParameter.mocks.stringValue();
18
- }
19
- }
20
- MockSsmParameter.mocks.stringValue.mockReturnValue('test-value');
21
- return { SsmParameter: MockSsmParameter };
22
- });
23
- const existingLayer = (0, ts_mockito_1.instance)((0, ts_mockito_1.mock)(aws_lambda_1.LayerVersion));
24
- const props = {
25
- runtime: aws_lambda_1.Runtime.NODEJS_18_X,
26
- handler: 'index.handler',
27
- code: aws_lambda_1.Code.fromInline('exports.handler = function(event, ctx, cb) { return cb(null, "hi"); }'),
28
- environment: { existingVar: 'existingValue' },
29
- layers: [existingLayer]
30
- };
31
- // Mock the wrapper object instead of the LayerVersion class
32
- beforeEach(() => {
33
- mockStack = (0, ts_mockito_1.mock)(DeployStack_1.DeployStack);
34
- mockLayer = (0, ts_mockito_1.mock)(aws_lambda_1.LayerVersion);
35
- fromLayerVersionArn = jest.spyOn(aws_lambda_1.LayerVersion, 'fromLayerVersionArn').mockReturnValue(mockLayer);
36
- });
37
- afterEach(() => {
38
- fromLayerVersionArn.mockRestore();
39
- });
40
- it('should add honeycomb layer to function props', () => {
41
- const result = (0, apply_honeycomb_to_lambda_1.applyHoneycombToLambda)((0, ts_mockito_1.instance)(mockStack), props);
42
- expect(result.layers).toContain(mockLayer);
43
- });
44
- it('should add honeycomb environment variables to function props', () => {
45
- const result = (0, apply_honeycomb_to_lambda_1.applyHoneycombToLambda)((0, ts_mockito_1.instance)(mockStack), props);
46
- expect(result.environment).toEqual(expect.objectContaining({
47
- LIBHONEY_API_KEY: 'test-value',
48
- LIBHONEY_DATASET: 'test-value',
49
- LOGS_API_DISABLE_PLATFORM_MSGS: 'true'
50
- }));
51
- });
52
- it('should not overwrite existing layers in function props', () => {
53
- const result = (0, apply_honeycomb_to_lambda_1.applyHoneycombToLambda)((0, ts_mockito_1.instance)(mockStack), props);
54
- expect(result.layers).toContain(existingLayer);
55
- });
56
- it('should not overwrite existing environment variables in function props', () => {
57
- const result = (0, apply_honeycomb_to_lambda_1.applyHoneycombToLambda)((0, ts_mockito_1.instance)(mockStack), props);
58
- expect(result.environment).toEqual(expect.objectContaining({
59
- existingVar: 'existingValue'
60
- }));
61
- });
@@ -1,13 +0,0 @@
1
- import { IIgnoreOptions } from "./walk-directory";
2
- export declare const defaultIgnore: IIgnoreOptions;
3
- interface IBuildOptions {
4
- dir?: string;
5
- ignore?: IIgnoreOptions;
6
- }
7
- export declare function buildNodeSource(type: string, id: string, options?: IBuildOptions): {
8
- buildDir: string;
9
- moduleChanged: boolean;
10
- packageChanged: boolean;
11
- sourceChanged: boolean;
12
- };
13
- export {};
@@ -1,105 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.buildNodeSource = exports.defaultIgnore = void 0;
30
- const path = __importStar(require("path"));
31
- const fse = __importStar(require("fs-extra"));
32
- const fs = __importStar(require("fs"));
33
- const child_process_1 = require("child_process");
34
- const generate_hash_1 = require("./generate-hash");
35
- const get_source_directory_1 = require("./get-source-directory");
36
- const duration_1 = __importDefault(require("./duration"));
37
- const empty_directory_1 = __importDefault(require("./empty-directory"));
38
- const distributionRoot = path.resolve(process.cwd(), "../dist");
39
- const hashRoot = path.join(distributionRoot, "hash");
40
- fse.ensureDirSync(hashRoot);
41
- exports.defaultIgnore = {
42
- included: (p) => {
43
- return !p.name.startsWith(".") &&
44
- !p.name.endsWith(".md") &&
45
- !p.name.includes(".test.") &&
46
- p.name !== 'package-lock.json';
47
- },
48
- childrenIncluded: (p) => {
49
- return p.name !== "node_modules";
50
- }
51
- };
52
- function buildNodeSource(type, id, options = {}) {
53
- const { dir = '' } = options;
54
- const ignore = {
55
- ...exports.defaultIgnore, ...options.ignore
56
- };
57
- const srcDir = (0, get_source_directory_1.getSourceDirectory)(type, id);
58
- const buildDir = (0, get_source_directory_1.getBuildDirectory)(type, id);
59
- const hashFilePath = path.join(hashRoot, `${type}-${id}-hash.txt`);
60
- const folderExists = fs.existsSync(buildDir);
61
- const hashFileExists = folderExists && fse.existsSync(hashFilePath);
62
- const prevHash = (hashFileExists ? fse.readJsonSync(hashFilePath) : {});
63
- const hash = (0, generate_hash_1.generateHash)(srcDir, { ignore });
64
- const nextHash = JSON.parse((0, generate_hash_1.generateHash)(srcDir, { ignore }));
65
- const moduleChanged = JSON.stringify(prevHash, null, '\t') !== hash;
66
- let packageChanged = false, sourceChanged = false;
67
- if (moduleChanged) {
68
- const prevPackageHash = findPackageHash(prevHash);
69
- const packageHash = findPackageHash(nextHash);
70
- packageChanged = prevPackageHash !== packageHash;
71
- sourceChanged = sourceWasUpdated(prevHash, nextHash);
72
- if (sourceChanged) {
73
- const rmComplete = (0, duration_1.default)();
74
- if (folderExists)
75
- (0, empty_directory_1.default)(buildDir, { childrenExcluded: folder => folder.name === 'node_modules' });
76
- console.log('Cleanup Duration (ms)', rmComplete());
77
- const copyComplete = (0, duration_1.default)();
78
- fse.copySync(srcDir, buildDir, {
79
- filter: src => !~src.indexOf("node_modules") && !src.endsWith('.test.js')
80
- });
81
- console.log('Copy Duration (ms)', copyComplete());
82
- }
83
- if (packageChanged) {
84
- const installComplete = (0, duration_1.default)();
85
- (0, child_process_1.execSync)("npm i --omit=dev --omit=optional --omit=peer --quite", {
86
- cwd: dir ? path.resolve(buildDir, dir) : buildDir
87
- });
88
- console.log('NPM Install Duration (ms)', installComplete());
89
- }
90
- fs.writeFileSync(hashFilePath, hash);
91
- }
92
- return { buildDir, packageChanged, sourceChanged, moduleChanged };
93
- }
94
- exports.buildNodeSource = buildNodeSource;
95
- function findPackageHash(hash) {
96
- return hash?.children?.find(file => file.name === 'package.json')?.hash;
97
- }
98
- function sourceWasUpdated(prevHash, nextHash) {
99
- const fileCountChanged = prevHash.children?.length != nextHash.children?.length;
100
- const updatedItem = prevHash.children?.find(prevFile => {
101
- const nextFile = nextHash.children?.find(f => f.name = prevFile.name);
102
- return prevFile.name !== 'package.json' && (!nextFile || nextFile.hash !== prevFile.hash);
103
- });
104
- return fileCountChanged || !!updatedItem;
105
- }
@@ -1,8 +0,0 @@
1
- declare const duration: (() => {
2
- (): number;
3
- time: [number, number];
4
- }) | (() => {
5
- (): number;
6
- time: number;
7
- });
8
- export default duration;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const hrDuration = () => {
4
- const startTime = process.hrtime();
5
- const onEnd = function duration() {
6
- const hrTime = process.hrtime(startTime);
7
- return hrTime[0] * 1000 + hrTime[1] / 1000000;
8
- };
9
- onEnd.time = startTime;
10
- return onEnd;
11
- };
12
- const msDuration = () => {
13
- const startTime = Date.now();
14
- const onEnd = function duration() {
15
- return Date.now() - startTime;
16
- };
17
- onEnd.time = startTime;
18
- return onEnd;
19
- };
20
- // @ts-ignore
21
- const duration = process.hrtime ? hrDuration : msDuration;
22
- exports.default = duration;
@@ -1,2 +0,0 @@
1
- import { IIgnoreOptions } from "./walk-directory";
2
- export default function emptyDirSync(parentFolder: string, options: IIgnoreOptions): void;
@@ -1,15 +0,0 @@
1
- import { IIgnoreOptions } from './walk-directory';
2
- interface HashOptions {
3
- ignore: IIgnoreOptions;
4
- }
5
- export interface HashResult {
6
- hash?: string;
7
- children?: HashItem[];
8
- }
9
- export interface HashItem {
10
- hash: string;
11
- path: string;
12
- name: string;
13
- }
14
- export declare function generateHash(folder: string, opt: HashOptions): string;
15
- export {};
@@ -1,59 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.generateHash = void 0;
30
- const crypto = __importStar(require("crypto"));
31
- const path = __importStar(require("path"));
32
- const fs = __importStar(require("fs"));
33
- const walk_directory_1 = __importDefault(require("./walk-directory"));
34
- const ALGO = 'sha1';
35
- const ENCODING = 'base64';
36
- function generateHash(folder, opt) {
37
- const files = (0, walk_directory_1.default)(folder, opt.ignore);
38
- const hash = crypto.createHash(ALGO);
39
- const children = files
40
- .sort((a, b) => a.fullpath().localeCompare(b.fullpath()))
41
- .map((child) => {
42
- const relPath = path.relative(process.cwd(), child.fullpath());
43
- const fileHash = crypto.createHash(ALGO);
44
- fileHash.update(relPath);
45
- fileHash.update(fs.readFileSync(child.fullpath()));
46
- const file = {
47
- name: child.name,
48
- path: relPath,
49
- hash: fileHash.digest(ENCODING)
50
- };
51
- hash.update(file.hash);
52
- return file;
53
- });
54
- return JSON.stringify({
55
- hash: hash.digest(ENCODING),
56
- children
57
- }, null, '\t');
58
- }
59
- exports.generateHash = generateHash;
@@ -1,4 +0,0 @@
1
- export declare const sourceRoot: string;
2
- export declare const distributionRoot: string;
3
- export declare function getSourceDirectory(type: string, id: string): string;
4
- export declare function getBuildDirectory(type: string, id: string): string;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getBuildDirectory = exports.getSourceDirectory = exports.distributionRoot = exports.sourceRoot = void 0;
27
- const path = __importStar(require("path"));
28
- exports.sourceRoot = path.resolve(process.cwd(), "../src");
29
- exports.distributionRoot = path.resolve(process.cwd(), "../dist");
30
- function getSourceDirectory(type, id) {
31
- return path.join(exports.sourceRoot, type, id);
32
- }
33
- exports.getSourceDirectory = getSourceDirectory;
34
- function getBuildDirectory(type, id) {
35
- return path.join(exports.distributionRoot, type, id);
36
- }
37
- exports.getBuildDirectory = getBuildDirectory;
@@ -1,14 +0,0 @@
1
- /// <reference types="node" />
2
- import * as fs from 'fs';
3
- export interface IIgnoreOptions {
4
- excluded?: (stat: fs.Dirent) => boolean;
5
- included?: (stat: fs.Dirent) => boolean;
6
- childrenExcluded?: (stat: fs.Dirent) => boolean;
7
- childrenIncluded?: (stat: fs.Dirent) => boolean;
8
- }
9
- export declare const yes: () => boolean;
10
- export declare const no: () => boolean;
11
- export default function walkDirectory(directory: string, options: IIgnoreOptions, filepaths?: DirentExtended[]): DirentExtended[];
12
- export interface DirentExtended extends fs.Dirent {
13
- fullpath: () => string;
14
- }
@@ -1,48 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.no = exports.yes = void 0;
27
- const path = __importStar(require("path"));
28
- const fs = __importStar(require("fs"));
29
- const yes = () => true;
30
- exports.yes = yes;
31
- const no = () => false;
32
- exports.no = no;
33
- function walkDirectory(directory, options, filepaths = []) {
34
- const { excluded = exports.no, included = exports.yes, childrenExcluded = exports.no, childrenIncluded = exports.yes } = options;
35
- const files = fs.readdirSync(directory, { withFileTypes: true });
36
- for (let stats of files) {
37
- const filepath = path.join(directory, stats.name);
38
- stats.fullpath = () => filepath;
39
- if (stats.isDirectory() && !childrenExcluded(stats) && childrenIncluded(stats)) {
40
- walkDirectory(filepath, options, filepaths);
41
- }
42
- else if (stats.isFile() && !excluded(stats) && included(stats)) {
43
- filepaths.push(stats);
44
- }
45
- }
46
- return filepaths;
47
- }
48
- exports.default = walkDirectory;
@@ -1 +0,0 @@
1
- <!doctype html><html><head><meta charset="utf-8"><meta http-equiv="Content-Type" content="text/html;charset=utf-8"><meta name="keywords" contect="jest, reporters"><meta name="author" contect="hazyzh"><meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1,maximum-scale=1"><link rel="shortcut icon" href="data:image/png;base64,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"></head><title>Report</title><body><div id="app"></div><script defer="defer" src="./jest-html-reporters-attach/index/index.js"></script></body></html>