@goldstack/template-ssr-server-compile-bundle 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Goldstack Server-Side Rendering Template Tools
2
+
3
+ For more information, see [Server-Side Rendering Template](https://goldstack.party/templates/ssr).
@@ -0,0 +1,21 @@
1
+ import { APIGatewayProxyResultV2 } from 'aws-lambda';
2
+ export interface CompileBundleResponse {
3
+ bundle: string;
4
+ sourceMap?: string;
5
+ metaFile?: string;
6
+ }
7
+ export declare const compileBundle: ({ entryPoint, metaFile, sourceMap, initialProperties, includeCss, }: {
8
+ entryPoint: string;
9
+ metaFile?: boolean | undefined;
10
+ sourceMap?: boolean | undefined;
11
+ initialProperties?: any;
12
+ includeCss: boolean;
13
+ }) => Promise<CompileBundleResponse>;
14
+ export declare const bundleResponse: ({ entryPoint, initialProperties, }: {
15
+ entryPoint: string;
16
+ initialProperties?: any;
17
+ }) => Promise<APIGatewayProxyResultV2>;
18
+ export declare const sourceMapResponse: ({ entryPoint, }: {
19
+ entryPoint: string;
20
+ }) => Promise<APIGatewayProxyResultV2>;
21
+ //# sourceMappingURL=templateSSRServerCompileBundle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templateSSRServerCompileBundle.d.ts","sourceRoot":"","sources":["../../src/templateSSRServerCompileBundle.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAsCrD,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;gBAOZ,MAAM;;;wBAGE,GAAG;gBACX,OAAO;MACjB,QAAQ,qBAAqB,CAyChC,CAAC;AAEF,eAAO,MAAM,cAAc;gBAIb,MAAM;wBACE,GAAG;MACrB,QAAQ,uBAAuB,CAkBlC,CAAC;AAoBF,eAAO,MAAM,iBAAiB;gBAGhB,MAAM;MAChB,QAAQ,uBAAuB,CAsBlC,CAAC"}
@@ -0,0 +1,140 @@
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.sourceMapResponse = exports.bundleResponse = exports.compileBundle = void 0;
7
+ const esbuild_1 = require("esbuild");
8
+ const esbuild_plugin_pnp_1 = require("@yarnpkg/esbuild-plugin-pnp");
9
+ const esbuild_css_modules_client_plugin_1 = __importDefault(require("esbuild-css-modules-client-plugin"));
10
+ const utils_sh_1 = require("@goldstack/utils-sh");
11
+ const path_1 = require("path");
12
+ const sharedConfig = (includeCss) => {
13
+ return {
14
+ plugins: [
15
+ (0, esbuild_css_modules_client_plugin_1.default)({
16
+ excludeCSSInject: !includeCss,
17
+ }),
18
+ (0, esbuild_plugin_pnp_1.pnpPlugin)(),
19
+ ],
20
+ bundle: true,
21
+ outfile: '/dist/tmp/bundle.js',
22
+ external: [
23
+ 'esbuild',
24
+ '@yarnpkg/esbuild-plugin-pnp',
25
+ '@swc/core',
26
+ '@swc/jest',
27
+ '@goldstack/template-ssr-server', // this is only required on the server side
28
+ ],
29
+ minify: true,
30
+ platform: 'browser',
31
+ format: 'iife',
32
+ treeShaking: true,
33
+ };
34
+ };
35
+ const getEsBuildConfig = (entryPoint) => {
36
+ const esbuildConfig = (0, utils_sh_1.readToType)('./esbuild.config.json');
37
+ const esbuildLocalPath = (0, utils_sh_1.changeExtension)((0, path_1.dirname)(entryPoint), '.esbuild.config.json');
38
+ const localEsbuildConfig = (0, utils_sh_1.readToType)(esbuildLocalPath);
39
+ return { ...esbuildConfig, ...localEsbuildConfig };
40
+ };
41
+ const getOutput = (extension, result) => {
42
+ const matchedFiles = result.outputFiles.filter((file) => file.path.endsWith(extension));
43
+ if (matchedFiles.length !== 1) {
44
+ throw new Error(`Invalid output from esbuild. Expected only one '${extension}' file but found ${matchedFiles.length}`);
45
+ }
46
+ const output = Buffer.from(matchedFiles[0].contents).toString('utf-8');
47
+ return output;
48
+ };
49
+ const compileBundle = async ({ entryPoint, metaFile, sourceMap, initialProperties, includeCss, }) => {
50
+ const res = await (0, esbuild_1.build)({
51
+ ...sharedConfig(includeCss),
52
+ entryPoints: [entryPoint],
53
+ metafile: metaFile,
54
+ sourcemap: sourceMap ? 'inline' : undefined,
55
+ ...getEsBuildConfig(entryPoint),
56
+ write: false,
57
+ });
58
+ const output = getOutput('.js', res);
59
+ let result = {
60
+ bundle: '',
61
+ };
62
+ if (!sourceMap) {
63
+ result.bundle = output;
64
+ }
65
+ else {
66
+ result.bundle = removeSourceMap(output);
67
+ }
68
+ if (initialProperties) {
69
+ result.bundle = `window.initialProperties = ${JSON.stringify(initialProperties)};${result.bundle}`;
70
+ }
71
+ if (metaFile) {
72
+ result = {
73
+ ...result,
74
+ metaFile: JSON.stringify(res.metafile),
75
+ };
76
+ }
77
+ if (sourceMap) {
78
+ result = {
79
+ ...result,
80
+ sourceMap: extractSourceMap(output),
81
+ };
82
+ }
83
+ return result;
84
+ };
85
+ exports.compileBundle = compileBundle;
86
+ const bundleResponse = async ({ entryPoint, initialProperties, }) => {
87
+ const res = await (0, exports.compileBundle)({
88
+ entryPoint,
89
+ initialProperties,
90
+ includeCss: true,
91
+ });
92
+ return {
93
+ statusCode: 201,
94
+ headers: {
95
+ 'Content-Type': 'application/javascript',
96
+ 'Cache-Control': 'no-cache, no-store, must-revalidate',
97
+ Pragma: 'no-cache',
98
+ Expire: '0',
99
+ SourceMap: '?resource=sourcemap',
100
+ },
101
+ body: res.bundle,
102
+ };
103
+ };
104
+ exports.bundleResponse = bundleResponse;
105
+ const extractSourceMap = (output) => {
106
+ const marker = '//# sourceMappingURL=data:application/json;base64,';
107
+ const startContent = output.indexOf(marker) + marker.length;
108
+ const sourceMapBase64Data = output.substring(startContent);
109
+ const sourceMapData = Buffer.from(sourceMapBase64Data, 'base64').toString('utf-8');
110
+ return sourceMapData;
111
+ };
112
+ const removeSourceMap = (output) => {
113
+ const marker = '//# sourceMappingURL=data:application/json;base64,';
114
+ const startContent = output.indexOf(marker);
115
+ const withoutSourceMap = output.substring(0, startContent);
116
+ return withoutSourceMap;
117
+ };
118
+ const sourceMapResponse = async ({ entryPoint, }) => {
119
+ const res = await (0, esbuild_1.build)({
120
+ ...sharedConfig(false),
121
+ entryPoints: [entryPoint],
122
+ sourcemap: 'inline',
123
+ ...getEsBuildConfig(entryPoint),
124
+ write: false,
125
+ });
126
+ const output = Buffer.from(res.outputFiles[0].contents).toString('utf-8');
127
+ const sourceMapData = extractSourceMap(output);
128
+ return {
129
+ statusCode: 201,
130
+ headers: {
131
+ 'Content-Type': 'application/json',
132
+ 'Cache-Control': 'no-cache, no-store, must-revalidate',
133
+ Pragma: 'no-cache',
134
+ Expire: '0',
135
+ },
136
+ body: sourceMapData,
137
+ };
138
+ };
139
+ exports.sourceMapResponse = sourceMapResponse;
140
+ //# sourceMappingURL=templateSSRServerCompileBundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templateSSRServerCompileBundle.js","sourceRoot":"","sources":["../../src/templateSSRServerCompileBundle.ts"],"names":[],"mappings":";;;;;;AAAA,qCAAgC;AAEhC,oEAAwD;AAExD,0GAA0D;AAG1D,kDAAkE;AAClE,+BAA+B;AAE/B,MAAM,YAAY,GAAG,CAAC,UAAmB,EAAgB,EAAE;IACzD,OAAO;QACL,OAAO,EAAE;YACP,IAAA,2CAAS,EAAC;gBACR,gBAAgB,EAAE,CAAC,UAAU;aAC9B,CAAC;YACF,IAAA,8BAAS,GAAE;SACZ;QACD,MAAM,EAAE,IAAI;QACZ,OAAO,EAAE,qBAAqB;QAC9B,QAAQ,EAAE;YACR,SAAS;YACT,6BAA6B;YAC7B,WAAW;YACX,WAAW;YACX,gCAAgC,EAAE,2CAA2C;SAC9E;QACD,MAAM,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,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;AA1BW,QAAA,iBAAiB,qBA0B5B"}
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "@goldstack/template-ssr-server-compile-bundle",
3
+ "version": "0.1.1",
4
+ "description": "Utility for compiling client side bundles for SSR application",
5
+ "keywords": [
6
+ "goldstack",
7
+ "utility",
8
+ "infrastructure",
9
+ "ssr",
10
+ "aws"
11
+ ],
12
+ "homepage": "https://goldstack.party",
13
+ "bugs": {
14
+ "url": "https://github.com/goldstack/goldstack/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/goldstack/goldstack.git"
19
+ },
20
+ "license": "MIT",
21
+ "author": "Max Rohde",
22
+ "sideEffects": false,
23
+ "main": "dist/src/templateSSRServerCompileBundle.js",
24
+ "scripts": {
25
+ "build": "yarn clean && yarn compile",
26
+ "build:watch": "yarn clean && yarn compile-watch",
27
+ "clean": "rimraf ./dist",
28
+ "compile": "tsc -p tsconfig.json",
29
+ "compile-watch": "tsc -p tsconfig.json --watch",
30
+ "compile-watch:light": "nodemon --watch ./src/ -e '*' --exec 'yarn compile'",
31
+ "coverage": "jest --collect-coverage --passWithNoTests --config=./jest.config.js --runInBand",
32
+ "prepublishOnly": "yarn run build",
33
+ "publish": "utils-git changed --exec \"yarn npm publish $@\"",
34
+ "test-ci": "jest --passWithNoTests --config=./jest.config.js --runInBand",
35
+ "version:apply": "utils-git changed --exec \"yarn version $@ && yarn version apply\"",
36
+ "version:apply:force": "yarn version $@ && yarn version apply"
37
+ },
38
+ "dependencies": {
39
+ "@goldstack/infra": "0.3.38",
40
+ "@goldstack/infra-aws": "0.3.47",
41
+ "@goldstack/utils-aws-lambda": "0.1.37",
42
+ "@goldstack/utils-esbuild": "0.4.3",
43
+ "@goldstack/utils-package": "0.3.41",
44
+ "@goldstack/utils-package-config-embedded": "0.4.5",
45
+ "@goldstack/utils-sh": "0.4.33",
46
+ "@goldstack/utils-template": "0.3.37",
47
+ "@goldstack/utils-terraform": "0.3.71",
48
+ "@yarnpkg/esbuild-plugin-pnp": "^3.0.0-rc.11",
49
+ "esbuild": "^0.14.48",
50
+ "esbuild-css-modules-client-plugin": "0.1.4",
51
+ "lambda-compression": "0.1.2",
52
+ "react": "^18.2.0",
53
+ "react-dom": "^18.2.0",
54
+ "source-map-support": "^0.5.21"
55
+ },
56
+ "devDependencies": {
57
+ "@goldstack/utils-docs-cli": "0.3.11",
58
+ "@goldstack/utils-git": "0.1.36",
59
+ "@goldstack/utils-package-config-generate": "0.2.17",
60
+ "@types/aws-lambda": "^8.10.88",
61
+ "@types/jest": "^27.5.1",
62
+ "@types/node": "^17.0.33",
63
+ "@types/react": "^18.0.15",
64
+ "@types/sha256": "^0",
65
+ "@types/yargs": "^17.0.10",
66
+ "jest": "^28.1.0",
67
+ "rimraf": "^3.0.2",
68
+ "ts-jest": "^28.0.2",
69
+ "ts-node": "^10.9.1",
70
+ "typescript": "^4.7.4"
71
+ },
72
+ "publishConfig": {
73
+ "main": "dist/src/templateSSRServerCompileBundle.js"
74
+ }
75
+ }