@goldstack/template-ssr-server-compile-bundle 0.1.3 → 0.1.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.
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
import type { BuildOptions } from 'esbuild';
|
|
2
2
|
import { APIGatewayProxyResultV2 } from 'aws-lambda';
|
|
3
|
-
|
|
4
|
-
|
|
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;
|
|
5
10
|
}
|
|
6
11
|
export interface CompileBundleResponse {
|
|
7
12
|
bundle: string;
|
|
8
13
|
sourceMap?: string;
|
|
9
14
|
metaFile?: string;
|
|
10
15
|
}
|
|
11
|
-
export declare const compileBundle: ({ entryPoint, metaFile,
|
|
16
|
+
export declare const compileBundle: ({ entryPoint, metaFile, buildOptions, buildConfig, }: {
|
|
12
17
|
entryPoint: string;
|
|
13
18
|
metaFile?: boolean | undefined;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
includeCss: boolean;
|
|
17
|
-
esbuildConfig: ESBuildConfiguration;
|
|
19
|
+
buildOptions: ClientBuildOptionsArgs;
|
|
20
|
+
buildConfig: BuildConfiguration;
|
|
18
21
|
}) => Promise<CompileBundleResponse>;
|
|
19
|
-
export declare const bundleResponse: ({ entryPoint,
|
|
22
|
+
export declare const bundleResponse: ({ entryPoint, buildConfig, }: {
|
|
20
23
|
entryPoint: string;
|
|
21
|
-
|
|
22
|
-
esbuildConfig: ESBuildConfiguration;
|
|
24
|
+
buildConfig: BuildConfiguration;
|
|
23
25
|
}) => Promise<APIGatewayProxyResultV2>;
|
|
24
|
-
export declare const sourceMapResponse: ({ entryPoint,
|
|
26
|
+
export declare const sourceMapResponse: ({ entryPoint, buildConfig, }: {
|
|
25
27
|
entryPoint: string;
|
|
26
|
-
|
|
28
|
+
buildConfig: BuildConfiguration;
|
|
27
29
|
}) => Promise<APIGatewayProxyResultV2>;
|
|
28
30
|
//# sourceMappingURL=templateSSRServerCompileBundle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templateSSRServerCompileBundle.d.ts","sourceRoot":"","sources":["../../src/templateSSRServerCompileBundle.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAA2B,MAAM,SAAS,CAAC;AAErE,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAIrD,MAAM,
|
|
1
|
+
{"version":3,"file":"templateSSRServerCompileBundle.d.ts","sourceRoot":"","sources":["../../src/templateSSRServerCompileBundle.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAA2B,MAAM,SAAS,CAAC;AAErE,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAIrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,KAAK,EACV,sBAAsB,EACtB,sBAAsB,EACvB,MAAM,6BAA6B,CAAC;AAErC,YAAY,EACV,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AAErC,MAAM,WAAW,kBAAkB;IACjC,gBAAgB,EAAE,uBAAuB,CAAC;IAC1C,wBAAwB,EAAE,CAAC,IAAI,EAAE,sBAAsB,KAAK,YAAY,CAAC;IACzE,wBAAwB,EAAE,CAAC,IAAI,EAAE,sBAAsB,KAAK,YAAY,CAAC;CAC1E;AAYD,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAsBD,eAAO,MAAM,aAAa;gBAMZ,MAAM;;kBAEJ,sBAAsB;iBACvB,kBAAkB;MAC7B,QAAQ,qBAAqB,CAsChC,CAAC;AAEF,eAAO,MAAM,cAAc;gBAIb,MAAM;iBACL,kBAAkB;MAC7B,QAAQ,uBAAuB,CAqBlC,CAAC;AAqBF,eAAO,MAAM,iBAAiB;gBAIhB,MAAM;iBACL,kBAAkB;MAC7B,QAAQ,uBAAuB,CAyBlC,CAAC"}
|
|
@@ -4,11 +4,11 @@ exports.sourceMapResponse = exports.bundleResponse = exports.compileBundle = voi
|
|
|
4
4
|
const esbuild_1 = require("esbuild");
|
|
5
5
|
const utils_sh_1 = require("@goldstack/utils-sh");
|
|
6
6
|
const path_1 = require("path");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const getBuildConfig = (entryPoint) => {
|
|
8
|
+
const buildConfig = (0, utils_sh_1.readToType)('./esbuild.config.json');
|
|
9
9
|
const esbuildLocalPath = (0, utils_sh_1.changeExtension)((0, path_1.dirname)(entryPoint), '.esbuild.config.json');
|
|
10
|
-
const
|
|
11
|
-
return { ...
|
|
10
|
+
const localBuildConfig = (0, utils_sh_1.readToType)(esbuildLocalPath);
|
|
11
|
+
return { ...buildConfig, ...localBuildConfig };
|
|
12
12
|
};
|
|
13
13
|
const getOutput = (extension, result) => {
|
|
14
14
|
const matchedFiles = result.outputFiles.filter((file) => file.path.endsWith(extension));
|
|
@@ -18,35 +18,35 @@ const getOutput = (extension, result) => {
|
|
|
18
18
|
const output = Buffer.from(matchedFiles[0].contents).toString('utf-8');
|
|
19
19
|
return output;
|
|
20
20
|
};
|
|
21
|
-
const compileBundle = async ({ entryPoint, metaFile,
|
|
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
|
+
}
|
|
22
26
|
const res = await (0, esbuild_1.build)({
|
|
23
|
-
...
|
|
27
|
+
...clientBuildConfig,
|
|
24
28
|
entryPoints: [entryPoint],
|
|
25
29
|
metafile: metaFile,
|
|
26
|
-
|
|
27
|
-
...getEsBuildConfig(entryPoint),
|
|
30
|
+
...getBuildConfig(entryPoint),
|
|
28
31
|
write: false,
|
|
29
32
|
});
|
|
30
33
|
const output = getOutput('.js', res);
|
|
31
34
|
let result = {
|
|
32
35
|
bundle: '',
|
|
33
36
|
};
|
|
34
|
-
if (!
|
|
37
|
+
if (!clientBuildConfig.sourcemap) {
|
|
35
38
|
result.bundle = output;
|
|
36
39
|
}
|
|
37
40
|
else {
|
|
38
41
|
result.bundle = removeSourceMap(output);
|
|
39
42
|
}
|
|
40
|
-
if (initialProperties) {
|
|
41
|
-
result.bundle = `window.initialProperties = ${JSON.stringify(initialProperties)};${result.bundle}`;
|
|
42
|
-
}
|
|
43
43
|
if (metaFile) {
|
|
44
44
|
result = {
|
|
45
45
|
...result,
|
|
46
46
|
metaFile: JSON.stringify(res.metafile),
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
if (
|
|
49
|
+
if (clientBuildConfig.sourcemap) {
|
|
50
50
|
result = {
|
|
51
51
|
...result,
|
|
52
52
|
sourceMap: extractSourceMap(output),
|
|
@@ -55,15 +55,17 @@ const compileBundle = async ({ entryPoint, metaFile, sourceMap, initialPropertie
|
|
|
55
55
|
return result;
|
|
56
56
|
};
|
|
57
57
|
exports.compileBundle = compileBundle;
|
|
58
|
-
const bundleResponse = async ({ entryPoint,
|
|
58
|
+
const bundleResponse = async ({ entryPoint, buildConfig, }) => {
|
|
59
59
|
const res = await (0, exports.compileBundle)({
|
|
60
60
|
entryPoint,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
buildOptions: {
|
|
62
|
+
deploymentName: 'local',
|
|
63
|
+
includeCss: true,
|
|
64
|
+
},
|
|
65
|
+
buildConfig,
|
|
64
66
|
});
|
|
65
67
|
return {
|
|
66
|
-
statusCode:
|
|
68
|
+
statusCode: 200,
|
|
67
69
|
headers: {
|
|
68
70
|
'Content-Type': 'application/javascript',
|
|
69
71
|
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
|
@@ -88,18 +90,21 @@ const removeSourceMap = (output) => {
|
|
|
88
90
|
const withoutSourceMap = output.substring(0, startContent);
|
|
89
91
|
return withoutSourceMap;
|
|
90
92
|
};
|
|
91
|
-
const sourceMapResponse = async ({ entryPoint,
|
|
93
|
+
const sourceMapResponse = async ({ entryPoint, buildConfig, }) => {
|
|
92
94
|
const res = await (0, esbuild_1.build)({
|
|
93
|
-
...
|
|
95
|
+
...buildConfig.createClientBuildOptions({
|
|
96
|
+
includeCss: false,
|
|
97
|
+
deploymentName: 'local',
|
|
98
|
+
}),
|
|
94
99
|
entryPoints: [entryPoint],
|
|
95
100
|
sourcemap: 'inline',
|
|
96
|
-
...
|
|
101
|
+
...getBuildConfig(entryPoint),
|
|
97
102
|
write: false,
|
|
98
103
|
});
|
|
99
104
|
const output = Buffer.from(res.outputFiles[0].contents).toString('utf-8');
|
|
100
105
|
const sourceMapData = extractSourceMap(output);
|
|
101
106
|
return {
|
|
102
|
-
statusCode:
|
|
107
|
+
statusCode: 200,
|
|
103
108
|
headers: {
|
|
104
109
|
'Content-Type': 'application/json',
|
|
105
110
|
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templateSSRServerCompileBundle.js","sourceRoot":"","sources":["../../src/templateSSRServerCompileBundle.ts"],"names":[],"mappings":";;;AAAA,qCAAgC;AAIhC,kDAAkE;AAClE,+BAA+B;
|
|
1
|
+
{"version":3,"file":"templateSSRServerCompileBundle.js","sourceRoot":"","sources":["../../src/templateS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EH,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC1E,MAAM,aAAa,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAE/C,OAAO;QACL,UAAU,EAAE,GAAG;QACf,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,eAAe,EAAE,qCAAqC;YACtD,MAAM,EAAE,UAAU;YAClB,MAAM,EAAE,GAAG;SACZ;QACD,IAAI,EAAE,aAAa;KACpB,CAAC;AACJ,CAAC,CAAC;AA/BW,QAAA,iBAAiB,qBA+B5B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goldstack/template-ssr-server-compile-bundle",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Utility for compiling client side bundles for SSR application",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"goldstack",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@goldstack/infra": "0.3.40",
|
|
40
40
|
"@goldstack/infra-aws": "0.3.49",
|
|
41
|
-
"@goldstack/utils-aws-lambda": "0.1.
|
|
41
|
+
"@goldstack/utils-aws-lambda": "0.1.40",
|
|
42
42
|
"@goldstack/utils-esbuild": "0.4.4",
|
|
43
43
|
"@goldstack/utils-package": "0.3.43",
|
|
44
44
|
"@goldstack/utils-package-config-embedded": "0.4.7",
|
|
@@ -49,7 +49,8 @@
|
|
|
49
49
|
"lambda-compression": "0.1.3",
|
|
50
50
|
"react": "^18.2.0",
|
|
51
51
|
"react-dom": "^18.2.0",
|
|
52
|
-
"source-map-support": "^0.5.21"
|
|
52
|
+
"source-map-support": "^0.5.21",
|
|
53
|
+
"static-file-mapper-build": "0.1.1"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
56
|
"@goldstack/utils-docs-cli": "0.3.11",
|