@goldstack/template-ssr-server-compile-bundle 0.3.0 → 0.3.3
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.
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import type { BuildOptions } from 'esbuild';
|
|
2
|
-
import { APIGatewayProxyResultV2 } from 'aws-lambda';
|
|
3
|
-
import { StaticFileMapperManager } from 'static-file-mapper-build';
|
|
4
|
-
import type { ClientBuildOptionsArgs, ServerBuildOptionsArgs } from '@goldstack/utils-aws-lambda';
|
|
5
|
-
export type { ClientBuildOptionsArgs, ServerBuildOptionsArgs, } from '@goldstack/utils-aws-lambda';
|
|
6
|
-
export interface BuildConfiguration {
|
|
7
|
-
staticFileMapper: StaticFileMapperManager;
|
|
8
|
-
createClientBuildOptions: (args: ClientBuildOptionsArgs) => BuildOptions;
|
|
9
|
-
createServerBuildOptions: (args: ServerBuildOptionsArgs) => BuildOptions;
|
|
10
|
-
}
|
|
11
|
-
export interface CompileBundleResponse {
|
|
12
|
-
bundle: string;
|
|
13
|
-
sourceMap?: string;
|
|
14
|
-
metaFile?: string;
|
|
15
|
-
}
|
|
16
|
-
export declare const compileBundle: ({ entryPoint, metaFile, buildOptions, buildConfig, }: {
|
|
17
|
-
entryPoint: string;
|
|
18
|
-
metaFile?: boolean | undefined;
|
|
19
|
-
buildOptions: ClientBuildOptionsArgs;
|
|
20
|
-
buildConfig: BuildConfiguration;
|
|
21
|
-
}) => Promise<CompileBundleResponse>;
|
|
22
|
-
export declare const bundleResponse: ({ entryPoint, buildConfig, }: {
|
|
23
|
-
entryPoint: string;
|
|
24
|
-
buildConfig: BuildConfiguration;
|
|
25
|
-
}) => Promise<APIGatewayProxyResultV2>;
|
|
26
|
-
export declare const sourceMapResponse: ({ entryPoint, buildConfig, }: {
|
|
27
|
-
entryPoint: string;
|
|
28
|
-
buildConfig: BuildConfiguration;
|
|
29
|
-
}) => Promise<APIGatewayProxyResultV2>;
|
|
1
|
+
import type { BuildOptions } from 'esbuild';
|
|
2
|
+
import { APIGatewayProxyResultV2 } from 'aws-lambda';
|
|
3
|
+
import { StaticFileMapperManager } from 'static-file-mapper-build';
|
|
4
|
+
import type { ClientBuildOptionsArgs, ServerBuildOptionsArgs } from '@goldstack/utils-aws-lambda';
|
|
5
|
+
export type { ClientBuildOptionsArgs, ServerBuildOptionsArgs, } from '@goldstack/utils-aws-lambda';
|
|
6
|
+
export interface BuildConfiguration {
|
|
7
|
+
staticFileMapper: StaticFileMapperManager;
|
|
8
|
+
createClientBuildOptions: (args: ClientBuildOptionsArgs) => BuildOptions;
|
|
9
|
+
createServerBuildOptions: (args: ServerBuildOptionsArgs) => BuildOptions;
|
|
10
|
+
}
|
|
11
|
+
export interface CompileBundleResponse {
|
|
12
|
+
bundle: string;
|
|
13
|
+
sourceMap?: string;
|
|
14
|
+
metaFile?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const compileBundle: ({ entryPoint, metaFile, buildOptions, buildConfig, }: {
|
|
17
|
+
entryPoint: string;
|
|
18
|
+
metaFile?: boolean | undefined;
|
|
19
|
+
buildOptions: ClientBuildOptionsArgs;
|
|
20
|
+
buildConfig: BuildConfiguration;
|
|
21
|
+
}) => Promise<CompileBundleResponse>;
|
|
22
|
+
export declare const bundleResponse: ({ entryPoint, buildConfig, }: {
|
|
23
|
+
entryPoint: string;
|
|
24
|
+
buildConfig: BuildConfiguration;
|
|
25
|
+
}) => Promise<APIGatewayProxyResultV2>;
|
|
26
|
+
export declare const sourceMapResponse: ({ entryPoint, buildConfig, }: {
|
|
27
|
+
entryPoint: string;
|
|
28
|
+
buildConfig: BuildConfiguration;
|
|
29
|
+
}) => Promise<APIGatewayProxyResultV2>;
|
|
30
30
|
//# sourceMappingURL=templateSSRServerCompileBundle.d.ts.map
|
|
@@ -1,118 +1,118 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sourceMapResponse = exports.bundleResponse = exports.compileBundle = void 0;
|
|
4
|
-
const esbuild_1 = require("esbuild");
|
|
5
|
-
const utils_sh_1 = require("@goldstack/utils-sh");
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
const getBuildConfig = (entryPoint) => {
|
|
8
|
-
const buildConfig = (0, utils_sh_1.readToType)('./esbuild.config.json');
|
|
9
|
-
const esbuildLocalPath = (0, utils_sh_1.changeExtension)((0, path_1.dirname)(entryPoint), '.esbuild.config.json');
|
|
10
|
-
const localBuildConfig = (0, utils_sh_1.readToType)(esbuildLocalPath);
|
|
11
|
-
return { ...buildConfig, ...localBuildConfig };
|
|
12
|
-
};
|
|
13
|
-
const getOutput = (extension, result) => {
|
|
14
|
-
const matchedFiles = result.outputFiles.filter((file) => file.path.endsWith(extension));
|
|
15
|
-
if (matchedFiles.length !== 1) {
|
|
16
|
-
throw new Error(`Invalid output from esbuild. Expected only one '${extension}' file but found ${matchedFiles.length}`);
|
|
17
|
-
}
|
|
18
|
-
const output = Buffer.from(matchedFiles[0].contents).toString('utf-8');
|
|
19
|
-
return output;
|
|
20
|
-
};
|
|
21
|
-
const compileBundle = async ({ entryPoint, metaFile, buildOptions, buildConfig, }) => {
|
|
22
|
-
const clientBuildConfig = buildConfig.createClientBuildOptions(buildOptions);
|
|
23
|
-
if (clientBuildConfig.sourcemap && clientBuildConfig.sourcemap !== 'inline') {
|
|
24
|
-
throw new Error('Only `inline` is supported for the `sourcemap` parameter');
|
|
25
|
-
}
|
|
26
|
-
const res = await (0, esbuild_1.build)({
|
|
27
|
-
...clientBuildConfig,
|
|
28
|
-
entryPoints: [entryPoint],
|
|
29
|
-
metafile: metaFile,
|
|
30
|
-
...getBuildConfig(entryPoint),
|
|
31
|
-
write: false,
|
|
32
|
-
});
|
|
33
|
-
const output = getOutput('.js', res);
|
|
34
|
-
let result = {
|
|
35
|
-
bundle: '',
|
|
36
|
-
};
|
|
37
|
-
if (!clientBuildConfig.sourcemap) {
|
|
38
|
-
result.bundle = output;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
result.bundle = removeSourceMap(output);
|
|
42
|
-
}
|
|
43
|
-
if (metaFile) {
|
|
44
|
-
result = {
|
|
45
|
-
...result,
|
|
46
|
-
metaFile: JSON.stringify(res.metafile),
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
if (clientBuildConfig.sourcemap) {
|
|
50
|
-
result = {
|
|
51
|
-
...result,
|
|
52
|
-
sourceMap: extractSourceMap(output),
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
return result;
|
|
56
|
-
};
|
|
57
|
-
exports.compileBundle = compileBundle;
|
|
58
|
-
const bundleResponse = async ({ entryPoint, buildConfig, }) => {
|
|
59
|
-
const res = await (0, exports.compileBundle)({
|
|
60
|
-
entryPoint,
|
|
61
|
-
buildOptions: {
|
|
62
|
-
deploymentName: 'local',
|
|
63
|
-
includeCss: true,
|
|
64
|
-
},
|
|
65
|
-
buildConfig,
|
|
66
|
-
});
|
|
67
|
-
return {
|
|
68
|
-
statusCode: 200,
|
|
69
|
-
headers: {
|
|
70
|
-
'Content-Type': 'application/javascript',
|
|
71
|
-
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
|
72
|
-
Pragma: 'no-cache',
|
|
73
|
-
Expire: '0',
|
|
74
|
-
SourceMap: '?resource=sourcemap',
|
|
75
|
-
},
|
|
76
|
-
body: res.bundle,
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
exports.bundleResponse = bundleResponse;
|
|
80
|
-
const extractSourceMap = (output) => {
|
|
81
|
-
const marker = '//# sourceMappingURL=data:application/json;base64,';
|
|
82
|
-
const startContent = output.indexOf(marker) + marker.length;
|
|
83
|
-
const sourceMapBase64Data = output.substring(startContent);
|
|
84
|
-
const sourceMapData = Buffer.from(sourceMapBase64Data, 'base64').toString('utf-8');
|
|
85
|
-
return sourceMapData;
|
|
86
|
-
};
|
|
87
|
-
const removeSourceMap = (output) => {
|
|
88
|
-
const marker = '//# sourceMappingURL=data:application/json;base64,';
|
|
89
|
-
const startContent = output.indexOf(marker);
|
|
90
|
-
const withoutSourceMap = output.substring(0, startContent);
|
|
91
|
-
return withoutSourceMap;
|
|
92
|
-
};
|
|
93
|
-
const sourceMapResponse = async ({ entryPoint, buildConfig, }) => {
|
|
94
|
-
const res = await (0, esbuild_1.build)({
|
|
95
|
-
...buildConfig.createClientBuildOptions({
|
|
96
|
-
includeCss: false,
|
|
97
|
-
deploymentName: 'local',
|
|
98
|
-
}),
|
|
99
|
-
entryPoints: [entryPoint],
|
|
100
|
-
sourcemap: 'inline',
|
|
101
|
-
...getBuildConfig(entryPoint),
|
|
102
|
-
write: false,
|
|
103
|
-
});
|
|
104
|
-
const output = Buffer.from(res.outputFiles[0].contents).toString('utf-8');
|
|
105
|
-
const sourceMapData = extractSourceMap(output);
|
|
106
|
-
return {
|
|
107
|
-
statusCode: 200,
|
|
108
|
-
headers: {
|
|
109
|
-
'Content-Type': 'application/json',
|
|
110
|
-
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
|
111
|
-
Pragma: 'no-cache',
|
|
112
|
-
Expire: '0',
|
|
113
|
-
},
|
|
114
|
-
body: sourceMapData,
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
exports.sourceMapResponse = sourceMapResponse;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sourceMapResponse = exports.bundleResponse = exports.compileBundle = void 0;
|
|
4
|
+
const esbuild_1 = require("esbuild");
|
|
5
|
+
const utils_sh_1 = require("@goldstack/utils-sh");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const getBuildConfig = (entryPoint) => {
|
|
8
|
+
const buildConfig = (0, utils_sh_1.readToType)('./esbuild.config.json');
|
|
9
|
+
const esbuildLocalPath = (0, utils_sh_1.changeExtension)((0, path_1.dirname)(entryPoint), '.esbuild.config.json');
|
|
10
|
+
const localBuildConfig = (0, utils_sh_1.readToType)(esbuildLocalPath);
|
|
11
|
+
return { ...buildConfig, ...localBuildConfig };
|
|
12
|
+
};
|
|
13
|
+
const getOutput = (extension, result) => {
|
|
14
|
+
const matchedFiles = result.outputFiles.filter((file) => file.path.endsWith(extension));
|
|
15
|
+
if (matchedFiles.length !== 1) {
|
|
16
|
+
throw new Error(`Invalid output from esbuild. Expected only one '${extension}' file but found ${matchedFiles.length}`);
|
|
17
|
+
}
|
|
18
|
+
const output = Buffer.from(matchedFiles[0].contents).toString('utf-8');
|
|
19
|
+
return output;
|
|
20
|
+
};
|
|
21
|
+
const compileBundle = async ({ entryPoint, metaFile, buildOptions, buildConfig, }) => {
|
|
22
|
+
const clientBuildConfig = buildConfig.createClientBuildOptions(buildOptions);
|
|
23
|
+
if (clientBuildConfig.sourcemap && clientBuildConfig.sourcemap !== 'inline') {
|
|
24
|
+
throw new Error('Only `inline` is supported for the `sourcemap` parameter');
|
|
25
|
+
}
|
|
26
|
+
const res = await (0, esbuild_1.build)({
|
|
27
|
+
...clientBuildConfig,
|
|
28
|
+
entryPoints: [entryPoint],
|
|
29
|
+
metafile: metaFile,
|
|
30
|
+
...getBuildConfig(entryPoint),
|
|
31
|
+
write: false,
|
|
32
|
+
});
|
|
33
|
+
const output = getOutput('.js', res);
|
|
34
|
+
let result = {
|
|
35
|
+
bundle: '',
|
|
36
|
+
};
|
|
37
|
+
if (!clientBuildConfig.sourcemap) {
|
|
38
|
+
result.bundle = output;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
result.bundle = removeSourceMap(output);
|
|
42
|
+
}
|
|
43
|
+
if (metaFile) {
|
|
44
|
+
result = {
|
|
45
|
+
...result,
|
|
46
|
+
metaFile: JSON.stringify(res.metafile),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (clientBuildConfig.sourcemap) {
|
|
50
|
+
result = {
|
|
51
|
+
...result,
|
|
52
|
+
sourceMap: extractSourceMap(output),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
};
|
|
57
|
+
exports.compileBundle = compileBundle;
|
|
58
|
+
const bundleResponse = async ({ entryPoint, buildConfig, }) => {
|
|
59
|
+
const res = await (0, exports.compileBundle)({
|
|
60
|
+
entryPoint,
|
|
61
|
+
buildOptions: {
|
|
62
|
+
deploymentName: 'local',
|
|
63
|
+
includeCss: true,
|
|
64
|
+
},
|
|
65
|
+
buildConfig,
|
|
66
|
+
});
|
|
67
|
+
return {
|
|
68
|
+
statusCode: 200,
|
|
69
|
+
headers: {
|
|
70
|
+
'Content-Type': 'application/javascript',
|
|
71
|
+
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
|
72
|
+
Pragma: 'no-cache',
|
|
73
|
+
Expire: '0',
|
|
74
|
+
SourceMap: '?resource=sourcemap',
|
|
75
|
+
},
|
|
76
|
+
body: res.bundle,
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
exports.bundleResponse = bundleResponse;
|
|
80
|
+
const extractSourceMap = (output) => {
|
|
81
|
+
const marker = '//# sourceMappingURL=data:application/json;base64,';
|
|
82
|
+
const startContent = output.indexOf(marker) + marker.length;
|
|
83
|
+
const sourceMapBase64Data = output.substring(startContent);
|
|
84
|
+
const sourceMapData = Buffer.from(sourceMapBase64Data, 'base64').toString('utf-8');
|
|
85
|
+
return sourceMapData;
|
|
86
|
+
};
|
|
87
|
+
const removeSourceMap = (output) => {
|
|
88
|
+
const marker = '//# sourceMappingURL=data:application/json;base64,';
|
|
89
|
+
const startContent = output.indexOf(marker);
|
|
90
|
+
const withoutSourceMap = output.substring(0, startContent);
|
|
91
|
+
return withoutSourceMap;
|
|
92
|
+
};
|
|
93
|
+
const sourceMapResponse = async ({ entryPoint, buildConfig, }) => {
|
|
94
|
+
const res = await (0, esbuild_1.build)({
|
|
95
|
+
...buildConfig.createClientBuildOptions({
|
|
96
|
+
includeCss: false,
|
|
97
|
+
deploymentName: 'local',
|
|
98
|
+
}),
|
|
99
|
+
entryPoints: [entryPoint],
|
|
100
|
+
sourcemap: 'inline',
|
|
101
|
+
...getBuildConfig(entryPoint),
|
|
102
|
+
write: false,
|
|
103
|
+
});
|
|
104
|
+
const output = Buffer.from(res.outputFiles[0].contents).toString('utf-8');
|
|
105
|
+
const sourceMapData = extractSourceMap(output);
|
|
106
|
+
return {
|
|
107
|
+
statusCode: 200,
|
|
108
|
+
headers: {
|
|
109
|
+
'Content-Type': 'application/json',
|
|
110
|
+
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
|
111
|
+
Pragma: 'no-cache',
|
|
112
|
+
Expire: '0',
|
|
113
|
+
},
|
|
114
|
+
body: sourceMapData,
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
exports.sourceMapResponse = sourceMapResponse;
|
|
118
118
|
//# sourceMappingURL=templateSSRServerCompileBundle.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goldstack/template-ssr-server-compile-bundle",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Utility for compiling client side bundles for SSR application",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"goldstack",
|
|
@@ -36,26 +36,26 @@
|
|
|
36
36
|
"version:apply:force": "yarn version $@ && yarn version apply"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@goldstack/infra": "0.4.
|
|
40
|
-
"@goldstack/infra-aws": "0.4.
|
|
41
|
-
"@goldstack/utils-aws-lambda": "0.3.
|
|
42
|
-
"@goldstack/utils-esbuild": "0.5.
|
|
43
|
-
"@goldstack/utils-package": "0.4.
|
|
44
|
-
"@goldstack/utils-package-config-embedded": "0.5.
|
|
45
|
-
"@goldstack/utils-sh": "0.5.
|
|
46
|
-
"@goldstack/utils-template": "0.4.
|
|
47
|
-
"@goldstack/utils-terraform": "0.4.
|
|
39
|
+
"@goldstack/infra": "0.4.1",
|
|
40
|
+
"@goldstack/infra-aws": "0.4.2",
|
|
41
|
+
"@goldstack/utils-aws-lambda": "0.3.2",
|
|
42
|
+
"@goldstack/utils-esbuild": "0.5.1",
|
|
43
|
+
"@goldstack/utils-package": "0.4.1",
|
|
44
|
+
"@goldstack/utils-package-config-embedded": "0.5.1",
|
|
45
|
+
"@goldstack/utils-sh": "0.5.1",
|
|
46
|
+
"@goldstack/utils-template": "0.4.1",
|
|
47
|
+
"@goldstack/utils-terraform": "0.4.2",
|
|
48
48
|
"esbuild": "^0.15.5",
|
|
49
|
-
"lambda-compression": "0.2.
|
|
49
|
+
"lambda-compression": "0.2.1",
|
|
50
50
|
"react": "^18.2.0",
|
|
51
51
|
"react-dom": "^18.2.0",
|
|
52
52
|
"source-map-support": "^0.5.21",
|
|
53
|
-
"static-file-mapper-build": "0.3.
|
|
53
|
+
"static-file-mapper-build": "0.3.2"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@goldstack/utils-docs-cli": "0.3.11",
|
|
57
|
-
"@goldstack/utils-git": "0.2.
|
|
58
|
-
"@goldstack/utils-package-config-generate": "0.3.
|
|
57
|
+
"@goldstack/utils-git": "0.2.1",
|
|
58
|
+
"@goldstack/utils-package-config-generate": "0.3.1",
|
|
59
59
|
"@types/aws-lambda": "^8.10.88",
|
|
60
60
|
"@types/jest": "^28.1.8",
|
|
61
61
|
"@types/node": "^18.7.13",
|