@awsless/awsless 0.0.9 → 0.0.10
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/bin.cjs +93 -90
- package/dist/bin.js +77 -74
- package/dist/index.cjs +3 -4
- package/dist/index.js +3 -4
- package/package.json +5 -1
package/dist/bin.cjs
CHANGED
|
@@ -382,54 +382,10 @@ var SizeSchema = import_zod7.z.custom((value) => {
|
|
|
382
382
|
return import_zod7.z.string().regex(/[0-9]+ (KB|MB|GB)/).safeParse(value).success;
|
|
383
383
|
}, "Invalid size").transform(toSize);
|
|
384
384
|
|
|
385
|
-
// src/plugins/function/util/esbuild.ts
|
|
386
|
-
var import_esbuild = require("esbuild");
|
|
387
|
-
var import_crypto = require("crypto");
|
|
388
|
-
var import_path3 = require("path");
|
|
389
|
-
var import_promises2 = require("fs/promises");
|
|
390
|
-
var defaultBuild = async (file) => {
|
|
391
|
-
const random = (0, import_crypto.randomUUID)();
|
|
392
|
-
const codeFile = (0, import_path3.join)(cacheDir, `${random}.mjs`);
|
|
393
|
-
const mapFile = (0, import_path3.join)(cacheDir, `${random}.mjs.map`);
|
|
394
|
-
await (0, import_esbuild.build)({
|
|
395
|
-
entryPoints: [file],
|
|
396
|
-
minify: true,
|
|
397
|
-
bundle: true,
|
|
398
|
-
external: [
|
|
399
|
-
"@aws-sdk/*",
|
|
400
|
-
"@aws-sdk",
|
|
401
|
-
"aws-sdk"
|
|
402
|
-
],
|
|
403
|
-
sourcemap: "external",
|
|
404
|
-
target: "esnext",
|
|
405
|
-
treeShaking: true,
|
|
406
|
-
// jsxSideEffects:
|
|
407
|
-
format: "esm",
|
|
408
|
-
platform: "node",
|
|
409
|
-
outfile: codeFile
|
|
410
|
-
});
|
|
411
|
-
const code = await (0, import_promises2.readFile)(codeFile, "utf8");
|
|
412
|
-
const map = await (0, import_promises2.readFile)(mapFile, "utf8");
|
|
413
|
-
await (0, import_promises2.rm)(codeFile);
|
|
414
|
-
await (0, import_promises2.rm)(mapFile);
|
|
415
|
-
const hash = (0, import_crypto.createHash)("sha1").update(code).digest("hex");
|
|
416
|
-
return {
|
|
417
|
-
handler: "index.default",
|
|
418
|
-
hash,
|
|
419
|
-
files: [
|
|
420
|
-
{
|
|
421
|
-
name: "index.mjs",
|
|
422
|
-
code,
|
|
423
|
-
map
|
|
424
|
-
}
|
|
425
|
-
]
|
|
426
|
-
};
|
|
427
|
-
};
|
|
428
|
-
|
|
429
385
|
// src/plugins/function/util/build.ts
|
|
430
386
|
var import_jszip = __toESM(require("jszip"), 1);
|
|
431
|
-
var
|
|
432
|
-
var
|
|
387
|
+
var import_path3 = require("path");
|
|
388
|
+
var import_promises2 = require("fs/promises");
|
|
433
389
|
var import_filesize = require("filesize");
|
|
434
390
|
var zipFiles = (files) => {
|
|
435
391
|
const zip = new import_jszip.default();
|
|
@@ -445,25 +401,25 @@ var zipFiles = (files) => {
|
|
|
445
401
|
});
|
|
446
402
|
};
|
|
447
403
|
var writeBuildHash = async (config2, stack, id, hash) => {
|
|
448
|
-
const funcPath = (0,
|
|
449
|
-
const versionFile = (0,
|
|
450
|
-
await (0,
|
|
404
|
+
const funcPath = (0, import_path3.join)(assetDir, "function", config2.name, stack.artifactId, id);
|
|
405
|
+
const versionFile = (0, import_path3.join)(funcPath, "HASH");
|
|
406
|
+
await (0, import_promises2.writeFile)(versionFile, hash);
|
|
451
407
|
};
|
|
452
408
|
var writeBuildFiles = async (config2, stack, id, files) => {
|
|
453
409
|
const bundle = await zipFiles(files);
|
|
454
|
-
const funcPath = (0,
|
|
455
|
-
const filesPath = (0,
|
|
456
|
-
const bundleFile = (0,
|
|
457
|
-
debug("Bundle size of", style.info((0,
|
|
458
|
-
await (0,
|
|
459
|
-
await (0,
|
|
410
|
+
const funcPath = (0, import_path3.join)(assetDir, "function", config2.name, stack.artifactId, id);
|
|
411
|
+
const filesPath = (0, import_path3.join)(funcPath, "files");
|
|
412
|
+
const bundleFile = (0, import_path3.join)(funcPath, "bundle.zip");
|
|
413
|
+
debug("Bundle size of", style.info((0, import_path3.join)(config2.name, stack.artifactId, id)), "is", style.attr((0, import_filesize.filesize)(bundle.byteLength)));
|
|
414
|
+
await (0, import_promises2.mkdir)(filesPath, { recursive: true });
|
|
415
|
+
await (0, import_promises2.writeFile)(bundleFile, bundle);
|
|
460
416
|
await Promise.all(files.map(async (file) => {
|
|
461
|
-
const fileName = (0,
|
|
462
|
-
await (0,
|
|
463
|
-
await (0,
|
|
417
|
+
const fileName = (0, import_path3.join)(filesPath, file.name);
|
|
418
|
+
await (0, import_promises2.mkdir)((0, import_path3.basename)(fileName), { recursive: true });
|
|
419
|
+
await (0, import_promises2.writeFile)(fileName, file.code);
|
|
464
420
|
if (file.map) {
|
|
465
|
-
const mapName = (0,
|
|
466
|
-
await (0,
|
|
421
|
+
const mapName = (0, import_path3.join)(filesPath, `${file.name}.map`);
|
|
422
|
+
await (0, import_promises2.writeFile)(mapName, file.map);
|
|
467
423
|
}
|
|
468
424
|
}));
|
|
469
425
|
return {
|
|
@@ -473,8 +429,8 @@ var writeBuildFiles = async (config2, stack, id, files) => {
|
|
|
473
429
|
};
|
|
474
430
|
|
|
475
431
|
// src/plugins/function/util/publish.ts
|
|
476
|
-
var
|
|
477
|
-
var
|
|
432
|
+
var import_path5 = require("path");
|
|
433
|
+
var import_promises3 = require("fs/promises");
|
|
478
434
|
var import_client_s3 = require("@aws-sdk/client-s3");
|
|
479
435
|
|
|
480
436
|
// src/stack/bootstrap.ts
|
|
@@ -514,11 +470,11 @@ var shouldDeployBootstrap = async (client, name) => {
|
|
|
514
470
|
var publishFunctionAsset = async (config2, stack, id) => {
|
|
515
471
|
const bucket = assetBucketName(config2);
|
|
516
472
|
const key = `${config2.name}/${stack.artifactId}/function/${id}.zip`;
|
|
517
|
-
const funcPath = (0,
|
|
518
|
-
const bundleFile = (0,
|
|
519
|
-
const hashFile = (0,
|
|
520
|
-
const hash = await (0,
|
|
521
|
-
const file = await (0,
|
|
473
|
+
const funcPath = (0, import_path5.join)(assetDir, "function", config2.name, stack.artifactId, id);
|
|
474
|
+
const bundleFile = (0, import_path5.join)(funcPath, "bundle.zip");
|
|
475
|
+
const hashFile = (0, import_path5.join)(funcPath, "HASH");
|
|
476
|
+
const hash = await (0, import_promises3.readFile)(hashFile, "utf8");
|
|
477
|
+
const file = await (0, import_promises3.readFile)(bundleFile);
|
|
522
478
|
const client = new import_client_s3.S3Client({
|
|
523
479
|
credentials: config2.credentials,
|
|
524
480
|
region: config2.region
|
|
@@ -562,6 +518,53 @@ var formatByteSize = (size) => {
|
|
|
562
518
|
return style.attr(number) + style.attr.dim(unit);
|
|
563
519
|
};
|
|
564
520
|
|
|
521
|
+
// src/plugins/function/util/bundler/rollup.ts
|
|
522
|
+
var import_rollup = require("rollup");
|
|
523
|
+
var import_crypto = require("crypto");
|
|
524
|
+
var import_rollup_plugin_swc3 = require("rollup-plugin-swc3");
|
|
525
|
+
var import_plugin_commonjs = __toESM(require("@rollup/plugin-commonjs"), 1);
|
|
526
|
+
var import_plugin_node_resolve = __toESM(require("@rollup/plugin-node-resolve"), 1);
|
|
527
|
+
var rollupBuild = async (input) => {
|
|
528
|
+
const bundle = await (0, import_rollup.rollup)({
|
|
529
|
+
input,
|
|
530
|
+
external: (importee) => {
|
|
531
|
+
return importee.startsWith("@aws-sdk") || importee.startsWith("aws-sdk");
|
|
532
|
+
},
|
|
533
|
+
onwarn: (error) => {
|
|
534
|
+
debugError(error.message);
|
|
535
|
+
},
|
|
536
|
+
treeshake: {
|
|
537
|
+
moduleSideEffects: (id) => input === id
|
|
538
|
+
},
|
|
539
|
+
plugins: [
|
|
540
|
+
(0, import_plugin_commonjs.default)({ sourceMap: true }),
|
|
541
|
+
(0, import_plugin_node_resolve.default)({
|
|
542
|
+
preferBuiltins: true
|
|
543
|
+
}),
|
|
544
|
+
(0, import_rollup_plugin_swc3.swc)({
|
|
545
|
+
minify: true,
|
|
546
|
+
jsc: { minify: { sourceMap: true } },
|
|
547
|
+
sourceMaps: true
|
|
548
|
+
})
|
|
549
|
+
]
|
|
550
|
+
});
|
|
551
|
+
const { output: [output] } = await bundle.generate({
|
|
552
|
+
format: "esm",
|
|
553
|
+
sourcemap: "hidden",
|
|
554
|
+
exports: "default"
|
|
555
|
+
});
|
|
556
|
+
const hash = (0, import_crypto.createHash)("sha1").update(output.code).digest("hex");
|
|
557
|
+
return {
|
|
558
|
+
handler: "index.default",
|
|
559
|
+
hash,
|
|
560
|
+
files: [{
|
|
561
|
+
name: "index.mjs",
|
|
562
|
+
code: output.code,
|
|
563
|
+
map: output.map?.toString()
|
|
564
|
+
}]
|
|
565
|
+
};
|
|
566
|
+
};
|
|
567
|
+
|
|
565
568
|
// src/plugins/function/index.ts
|
|
566
569
|
var FunctionSchema = import_zod9.z.union([
|
|
567
570
|
LocalFileSchema,
|
|
@@ -626,7 +629,7 @@ var toFunction = ({ config: config2, stack, assets }, id, fileOrProps) => {
|
|
|
626
629
|
resource: "function",
|
|
627
630
|
resourceName: id,
|
|
628
631
|
async build() {
|
|
629
|
-
const result = await
|
|
632
|
+
const result = await rollupBuild(props.file);
|
|
630
633
|
const bundle = await writeBuildFiles(config2, stack, id, result.files);
|
|
631
634
|
await writeBuildHash(config2, stack, id, result.hash);
|
|
632
635
|
const func = lambda.node.defaultChild;
|
|
@@ -941,7 +944,7 @@ var searchPlugin = definePlugin({
|
|
|
941
944
|
var import_zod21 = require("zod");
|
|
942
945
|
var import_aws_appsync = require("aws-cdk-lib/aws-appsync");
|
|
943
946
|
var import_merge = require("@graphql-tools/merge");
|
|
944
|
-
var
|
|
947
|
+
var import_promises4 = require("fs/promises");
|
|
945
948
|
|
|
946
949
|
// src/util/array.ts
|
|
947
950
|
var toArray = (value) => {
|
|
@@ -952,7 +955,7 @@ var toArray = (value) => {
|
|
|
952
955
|
};
|
|
953
956
|
|
|
954
957
|
// src/plugins/graphql/index.ts
|
|
955
|
-
var
|
|
958
|
+
var import_path6 = require("path");
|
|
956
959
|
var import_graphql = require("graphql");
|
|
957
960
|
var import_change_case2 = require("change-case");
|
|
958
961
|
|
|
@@ -997,7 +1000,7 @@ var graphqlPlugin = definePlugin({
|
|
|
997
1000
|
});
|
|
998
1001
|
});
|
|
999
1002
|
list3.forEach((id) => {
|
|
1000
|
-
const file = (0,
|
|
1003
|
+
const file = (0, import_path6.join)(assetDir, "graphql", config2.name, id, "schema.graphql");
|
|
1001
1004
|
const authorization = config2.defaults.graphql?.[id]?.authorization;
|
|
1002
1005
|
const authProps = {};
|
|
1003
1006
|
if (authorization) {
|
|
@@ -1028,13 +1031,13 @@ var graphqlPlugin = definePlugin({
|
|
|
1028
1031
|
await Promise.all(Object.values(config2.stacks).map(async (stackConfig) => {
|
|
1029
1032
|
const schemaFiles = toArray(stackConfig.graphql?.[id].schema || []);
|
|
1030
1033
|
await Promise.all(schemaFiles.map(async (schemaFile) => {
|
|
1031
|
-
const schema3 = await (0,
|
|
1034
|
+
const schema3 = await (0, import_promises4.readFile)(schemaFile, "utf8");
|
|
1032
1035
|
schemas.push(schema3);
|
|
1033
1036
|
}));
|
|
1034
1037
|
}));
|
|
1035
1038
|
const schema2 = (0, import_graphql.print)((0, import_merge.mergeTypeDefs)(schemas));
|
|
1036
|
-
await (0,
|
|
1037
|
-
await (0,
|
|
1039
|
+
await (0, import_promises4.mkdir)((0, import_path6.dirname)(file), { recursive: true });
|
|
1040
|
+
await (0, import_promises4.writeFile)(file, schema2);
|
|
1038
1041
|
new import_aws_appsync.CfnGraphQLSchema(stack, toId("schema", id), {
|
|
1039
1042
|
apiId: api.attrApiId,
|
|
1040
1043
|
definition: schema2
|
|
@@ -1316,7 +1319,7 @@ var footer = () => {
|
|
|
1316
1319
|
};
|
|
1317
1320
|
|
|
1318
1321
|
// src/config.ts
|
|
1319
|
-
var
|
|
1322
|
+
var import_path11 = require("path");
|
|
1320
1323
|
|
|
1321
1324
|
// src/util/account.ts
|
|
1322
1325
|
var import_client_sts = require("@aws-sdk/client-sts");
|
|
@@ -1389,8 +1392,8 @@ var AppSchema = import_zod25.z.object({
|
|
|
1389
1392
|
|
|
1390
1393
|
// src/util/import.ts
|
|
1391
1394
|
var import_core3 = require("@swc/core");
|
|
1392
|
-
var
|
|
1393
|
-
var
|
|
1395
|
+
var import_path9 = require("path");
|
|
1396
|
+
var import_promises5 = require("fs/promises");
|
|
1394
1397
|
var resolveFileNameExtension = async (path) => {
|
|
1395
1398
|
const options = [
|
|
1396
1399
|
"",
|
|
@@ -1403,7 +1406,7 @@ var resolveFileNameExtension = async (path) => {
|
|
|
1403
1406
|
const file = path + option;
|
|
1404
1407
|
let stat;
|
|
1405
1408
|
try {
|
|
1406
|
-
stat = await (0,
|
|
1409
|
+
stat = await (0, import_promises5.lstat)(file);
|
|
1407
1410
|
} catch (error) {
|
|
1408
1411
|
continue;
|
|
1409
1412
|
}
|
|
@@ -1414,14 +1417,14 @@ var resolveFileNameExtension = async (path) => {
|
|
|
1414
1417
|
throw new Error(`Failed to load file: ${path}`);
|
|
1415
1418
|
};
|
|
1416
1419
|
var resolveDir = (path) => {
|
|
1417
|
-
return (0,
|
|
1420
|
+
return (0, import_path9.dirname)(path).replace(rootDir + "/", "");
|
|
1418
1421
|
};
|
|
1419
1422
|
var importFile = async (path) => {
|
|
1420
1423
|
const load = async (file) => {
|
|
1421
1424
|
let { code: code2 } = await (0, import_core3.transformFile)(file, {
|
|
1422
1425
|
isModule: true
|
|
1423
1426
|
});
|
|
1424
|
-
const path2 = (0,
|
|
1427
|
+
const path2 = (0, import_path9.dirname)(file);
|
|
1425
1428
|
const dir = resolveDir(file);
|
|
1426
1429
|
code2 = code2.replaceAll("__dirname", `"${dir}"`);
|
|
1427
1430
|
const matches = code2.match(/import\s*{\s*[a-z0-9\_]+\s*}\s*from\s*('|")(\.[\/a-z0-9\_\-]+)('|");?/ig);
|
|
@@ -1430,23 +1433,23 @@ var importFile = async (path) => {
|
|
|
1430
1433
|
await Promise.all(matches?.map(async (match) => {
|
|
1431
1434
|
const parts = /('|")(\.[\/a-z0-9\_\-]+)('|")/ig.exec(match);
|
|
1432
1435
|
const from = parts[2];
|
|
1433
|
-
const file2 = await resolveFileNameExtension((0,
|
|
1436
|
+
const file2 = await resolveFileNameExtension((0, import_path9.join)(path2, from));
|
|
1434
1437
|
const result = await load(file2);
|
|
1435
1438
|
code2 = code2.replace(match, result);
|
|
1436
1439
|
}));
|
|
1437
1440
|
return code2;
|
|
1438
1441
|
};
|
|
1439
1442
|
const code = await load(path);
|
|
1440
|
-
const outputFile = (0,
|
|
1441
|
-
await (0,
|
|
1442
|
-
await (0,
|
|
1443
|
+
const outputFile = (0, import_path9.join)(outDir, "config.js");
|
|
1444
|
+
await (0, import_promises5.mkdir)(outDir, { recursive: true });
|
|
1445
|
+
await (0, import_promises5.writeFile)(outputFile, code);
|
|
1443
1446
|
return import(outputFile);
|
|
1444
1447
|
};
|
|
1445
1448
|
|
|
1446
1449
|
// src/config.ts
|
|
1447
1450
|
var importConfig = async (options) => {
|
|
1448
1451
|
debug("Import config file");
|
|
1449
|
-
const fileName = (0,
|
|
1452
|
+
const fileName = (0, import_path11.join)(process.cwd(), options.configFile || "awsless.config.ts");
|
|
1450
1453
|
const module2 = await importFile(fileName);
|
|
1451
1454
|
const appConfig = typeof module2.default === "function" ? await module2.default({
|
|
1452
1455
|
profile: options.profile,
|
|
@@ -1914,7 +1917,7 @@ var assetBuilder = (assets) => {
|
|
|
1914
1917
|
};
|
|
1915
1918
|
|
|
1916
1919
|
// src/util/cleanup.ts
|
|
1917
|
-
var
|
|
1920
|
+
var import_promises6 = require("fs/promises");
|
|
1918
1921
|
var cleanUp = async () => {
|
|
1919
1922
|
debug("Clean up assembly & asset files");
|
|
1920
1923
|
const paths = [
|
|
@@ -1922,18 +1925,18 @@ var cleanUp = async () => {
|
|
|
1922
1925
|
assetDir,
|
|
1923
1926
|
cacheDir
|
|
1924
1927
|
];
|
|
1925
|
-
await Promise.all(paths.map((path) => (0,
|
|
1928
|
+
await Promise.all(paths.map((path) => (0, import_promises6.rm)(path, {
|
|
1926
1929
|
recursive: true,
|
|
1927
1930
|
force: true,
|
|
1928
1931
|
maxRetries: 2
|
|
1929
1932
|
})));
|
|
1930
|
-
await Promise.all(paths.map((path) => (0,
|
|
1933
|
+
await Promise.all(paths.map((path) => (0, import_promises6.mkdir)(path, {
|
|
1931
1934
|
recursive: true
|
|
1932
1935
|
})));
|
|
1933
1936
|
};
|
|
1934
1937
|
|
|
1935
1938
|
// src/cli/command/build.ts
|
|
1936
|
-
var
|
|
1939
|
+
var build = (program2) => {
|
|
1937
1940
|
program2.command("build").argument("[stack...]", "Optionally filter stacks to build").description("Build your app").action(async (filters) => {
|
|
1938
1941
|
await layout(async (config2, write) => {
|
|
1939
1942
|
const { app, assets } = await toApp(config2, filters);
|
|
@@ -2529,7 +2532,7 @@ program.on("option:verbose", () => {
|
|
|
2529
2532
|
var commands2 = [
|
|
2530
2533
|
bootstrap,
|
|
2531
2534
|
status,
|
|
2532
|
-
|
|
2535
|
+
build,
|
|
2533
2536
|
deploy,
|
|
2534
2537
|
config
|
|
2535
2538
|
// diff,
|
package/dist/bin.js
CHANGED
|
@@ -359,53 +359,9 @@ var SizeSchema = z7.custom((value) => {
|
|
|
359
359
|
return z7.string().regex(/[0-9]+ (KB|MB|GB)/).safeParse(value).success;
|
|
360
360
|
}, "Invalid size").transform(toSize);
|
|
361
361
|
|
|
362
|
-
// src/plugins/function/util/esbuild.ts
|
|
363
|
-
import { build } from "esbuild";
|
|
364
|
-
import { createHash, randomUUID } from "crypto";
|
|
365
|
-
import { join as join2 } from "path";
|
|
366
|
-
import { readFile, rm } from "fs/promises";
|
|
367
|
-
var defaultBuild = async (file) => {
|
|
368
|
-
const random = randomUUID();
|
|
369
|
-
const codeFile = join2(cacheDir, `${random}.mjs`);
|
|
370
|
-
const mapFile = join2(cacheDir, `${random}.mjs.map`);
|
|
371
|
-
await build({
|
|
372
|
-
entryPoints: [file],
|
|
373
|
-
minify: true,
|
|
374
|
-
bundle: true,
|
|
375
|
-
external: [
|
|
376
|
-
"@aws-sdk/*",
|
|
377
|
-
"@aws-sdk",
|
|
378
|
-
"aws-sdk"
|
|
379
|
-
],
|
|
380
|
-
sourcemap: "external",
|
|
381
|
-
target: "esnext",
|
|
382
|
-
treeShaking: true,
|
|
383
|
-
// jsxSideEffects:
|
|
384
|
-
format: "esm",
|
|
385
|
-
platform: "node",
|
|
386
|
-
outfile: codeFile
|
|
387
|
-
});
|
|
388
|
-
const code = await readFile(codeFile, "utf8");
|
|
389
|
-
const map = await readFile(mapFile, "utf8");
|
|
390
|
-
await rm(codeFile);
|
|
391
|
-
await rm(mapFile);
|
|
392
|
-
const hash = createHash("sha1").update(code).digest("hex");
|
|
393
|
-
return {
|
|
394
|
-
handler: "index.default",
|
|
395
|
-
hash,
|
|
396
|
-
files: [
|
|
397
|
-
{
|
|
398
|
-
name: "index.mjs",
|
|
399
|
-
code,
|
|
400
|
-
map
|
|
401
|
-
}
|
|
402
|
-
]
|
|
403
|
-
};
|
|
404
|
-
};
|
|
405
|
-
|
|
406
362
|
// src/plugins/function/util/build.ts
|
|
407
363
|
import JSZip from "jszip";
|
|
408
|
-
import { basename, join as
|
|
364
|
+
import { basename, join as join2 } from "path";
|
|
409
365
|
import { mkdir, writeFile } from "fs/promises";
|
|
410
366
|
import { filesize } from "filesize";
|
|
411
367
|
var zipFiles = (files) => {
|
|
@@ -422,24 +378,24 @@ var zipFiles = (files) => {
|
|
|
422
378
|
});
|
|
423
379
|
};
|
|
424
380
|
var writeBuildHash = async (config2, stack, id, hash) => {
|
|
425
|
-
const funcPath =
|
|
426
|
-
const versionFile =
|
|
381
|
+
const funcPath = join2(assetDir, "function", config2.name, stack.artifactId, id);
|
|
382
|
+
const versionFile = join2(funcPath, "HASH");
|
|
427
383
|
await writeFile(versionFile, hash);
|
|
428
384
|
};
|
|
429
385
|
var writeBuildFiles = async (config2, stack, id, files) => {
|
|
430
386
|
const bundle = await zipFiles(files);
|
|
431
|
-
const funcPath =
|
|
432
|
-
const filesPath =
|
|
433
|
-
const bundleFile =
|
|
434
|
-
debug("Bundle size of", style.info(
|
|
387
|
+
const funcPath = join2(assetDir, "function", config2.name, stack.artifactId, id);
|
|
388
|
+
const filesPath = join2(funcPath, "files");
|
|
389
|
+
const bundleFile = join2(funcPath, "bundle.zip");
|
|
390
|
+
debug("Bundle size of", style.info(join2(config2.name, stack.artifactId, id)), "is", style.attr(filesize(bundle.byteLength)));
|
|
435
391
|
await mkdir(filesPath, { recursive: true });
|
|
436
392
|
await writeFile(bundleFile, bundle);
|
|
437
393
|
await Promise.all(files.map(async (file) => {
|
|
438
|
-
const fileName =
|
|
394
|
+
const fileName = join2(filesPath, file.name);
|
|
439
395
|
await mkdir(basename(fileName), { recursive: true });
|
|
440
396
|
await writeFile(fileName, file.code);
|
|
441
397
|
if (file.map) {
|
|
442
|
-
const mapName =
|
|
398
|
+
const mapName = join2(filesPath, `${file.name}.map`);
|
|
443
399
|
await writeFile(mapName, file.map);
|
|
444
400
|
}
|
|
445
401
|
}));
|
|
@@ -450,8 +406,8 @@ var writeBuildFiles = async (config2, stack, id, files) => {
|
|
|
450
406
|
};
|
|
451
407
|
|
|
452
408
|
// src/plugins/function/util/publish.ts
|
|
453
|
-
import { join as
|
|
454
|
-
import { readFile
|
|
409
|
+
import { join as join3 } from "path";
|
|
410
|
+
import { readFile } from "fs/promises";
|
|
455
411
|
import { GetObjectCommand, ObjectCannedACL, PutObjectCommand, S3Client, StorageClass } from "@aws-sdk/client-s3";
|
|
456
412
|
|
|
457
413
|
// src/stack/bootstrap.ts
|
|
@@ -491,11 +447,11 @@ var shouldDeployBootstrap = async (client, name) => {
|
|
|
491
447
|
var publishFunctionAsset = async (config2, stack, id) => {
|
|
492
448
|
const bucket = assetBucketName(config2);
|
|
493
449
|
const key = `${config2.name}/${stack.artifactId}/function/${id}.zip`;
|
|
494
|
-
const funcPath =
|
|
495
|
-
const bundleFile =
|
|
496
|
-
const hashFile =
|
|
497
|
-
const hash = await
|
|
498
|
-
const file = await
|
|
450
|
+
const funcPath = join3(assetDir, "function", config2.name, stack.artifactId, id);
|
|
451
|
+
const bundleFile = join3(funcPath, "bundle.zip");
|
|
452
|
+
const hashFile = join3(funcPath, "HASH");
|
|
453
|
+
const hash = await readFile(hashFile, "utf8");
|
|
454
|
+
const file = await readFile(bundleFile);
|
|
499
455
|
const client = new S3Client({
|
|
500
456
|
credentials: config2.credentials,
|
|
501
457
|
region: config2.region
|
|
@@ -539,6 +495,53 @@ var formatByteSize = (size) => {
|
|
|
539
495
|
return style.attr(number) + style.attr.dim(unit);
|
|
540
496
|
};
|
|
541
497
|
|
|
498
|
+
// src/plugins/function/util/bundler/rollup.ts
|
|
499
|
+
import { rollup } from "rollup";
|
|
500
|
+
import { createHash } from "crypto";
|
|
501
|
+
import { swc } from "rollup-plugin-swc3";
|
|
502
|
+
import commonjs from "@rollup/plugin-commonjs";
|
|
503
|
+
import nodeResolve from "@rollup/plugin-node-resolve";
|
|
504
|
+
var rollupBuild = async (input) => {
|
|
505
|
+
const bundle = await rollup({
|
|
506
|
+
input,
|
|
507
|
+
external: (importee) => {
|
|
508
|
+
return importee.startsWith("@aws-sdk") || importee.startsWith("aws-sdk");
|
|
509
|
+
},
|
|
510
|
+
onwarn: (error) => {
|
|
511
|
+
debugError(error.message);
|
|
512
|
+
},
|
|
513
|
+
treeshake: {
|
|
514
|
+
moduleSideEffects: (id) => input === id
|
|
515
|
+
},
|
|
516
|
+
plugins: [
|
|
517
|
+
commonjs({ sourceMap: true }),
|
|
518
|
+
nodeResolve({
|
|
519
|
+
preferBuiltins: true
|
|
520
|
+
}),
|
|
521
|
+
swc({
|
|
522
|
+
minify: true,
|
|
523
|
+
jsc: { minify: { sourceMap: true } },
|
|
524
|
+
sourceMaps: true
|
|
525
|
+
})
|
|
526
|
+
]
|
|
527
|
+
});
|
|
528
|
+
const { output: [output] } = await bundle.generate({
|
|
529
|
+
format: "esm",
|
|
530
|
+
sourcemap: "hidden",
|
|
531
|
+
exports: "default"
|
|
532
|
+
});
|
|
533
|
+
const hash = createHash("sha1").update(output.code).digest("hex");
|
|
534
|
+
return {
|
|
535
|
+
handler: "index.default",
|
|
536
|
+
hash,
|
|
537
|
+
files: [{
|
|
538
|
+
name: "index.mjs",
|
|
539
|
+
code: output.code,
|
|
540
|
+
map: output.map?.toString()
|
|
541
|
+
}]
|
|
542
|
+
};
|
|
543
|
+
};
|
|
544
|
+
|
|
542
545
|
// src/plugins/function/index.ts
|
|
543
546
|
var FunctionSchema = z9.union([
|
|
544
547
|
LocalFileSchema,
|
|
@@ -603,7 +606,7 @@ var toFunction = ({ config: config2, stack, assets }, id, fileOrProps) => {
|
|
|
603
606
|
resource: "function",
|
|
604
607
|
resourceName: id,
|
|
605
608
|
async build() {
|
|
606
|
-
const result = await
|
|
609
|
+
const result = await rollupBuild(props.file);
|
|
607
610
|
const bundle = await writeBuildFiles(config2, stack, id, result.files);
|
|
608
611
|
await writeBuildHash(config2, stack, id, result.hash);
|
|
609
612
|
const func = lambda.node.defaultChild;
|
|
@@ -918,7 +921,7 @@ var searchPlugin = definePlugin({
|
|
|
918
921
|
import { z as z21 } from "zod";
|
|
919
922
|
import { AuthorizationType, CfnGraphQLApi, CfnGraphQLSchema, GraphqlApi, MappingTemplate } from "aws-cdk-lib/aws-appsync";
|
|
920
923
|
import { mergeTypeDefs } from "@graphql-tools/merge";
|
|
921
|
-
import { mkdir as mkdir2, readFile as
|
|
924
|
+
import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
|
|
922
925
|
|
|
923
926
|
// src/util/array.ts
|
|
924
927
|
var toArray = (value) => {
|
|
@@ -929,7 +932,7 @@ var toArray = (value) => {
|
|
|
929
932
|
};
|
|
930
933
|
|
|
931
934
|
// src/plugins/graphql/index.ts
|
|
932
|
-
import { dirname, join as
|
|
935
|
+
import { dirname, join as join4 } from "path";
|
|
933
936
|
import { print } from "graphql";
|
|
934
937
|
import { paramCase as paramCase2 } from "change-case";
|
|
935
938
|
|
|
@@ -974,7 +977,7 @@ var graphqlPlugin = definePlugin({
|
|
|
974
977
|
});
|
|
975
978
|
});
|
|
976
979
|
list3.forEach((id) => {
|
|
977
|
-
const file =
|
|
980
|
+
const file = join4(assetDir, "graphql", config2.name, id, "schema.graphql");
|
|
978
981
|
const authorization = config2.defaults.graphql?.[id]?.authorization;
|
|
979
982
|
const authProps = {};
|
|
980
983
|
if (authorization) {
|
|
@@ -1005,7 +1008,7 @@ var graphqlPlugin = definePlugin({
|
|
|
1005
1008
|
await Promise.all(Object.values(config2.stacks).map(async (stackConfig) => {
|
|
1006
1009
|
const schemaFiles = toArray(stackConfig.graphql?.[id].schema || []);
|
|
1007
1010
|
await Promise.all(schemaFiles.map(async (schemaFile) => {
|
|
1008
|
-
const schema3 = await
|
|
1011
|
+
const schema3 = await readFile2(schemaFile, "utf8");
|
|
1009
1012
|
schemas.push(schema3);
|
|
1010
1013
|
}));
|
|
1011
1014
|
}));
|
|
@@ -1293,7 +1296,7 @@ var footer = () => {
|
|
|
1293
1296
|
};
|
|
1294
1297
|
|
|
1295
1298
|
// src/config.ts
|
|
1296
|
-
import { join as
|
|
1299
|
+
import { join as join6 } from "path";
|
|
1297
1300
|
|
|
1298
1301
|
// src/util/account.ts
|
|
1299
1302
|
import { STSClient, GetCallerIdentityCommand } from "@aws-sdk/client-sts";
|
|
@@ -1366,7 +1369,7 @@ var AppSchema = z25.object({
|
|
|
1366
1369
|
|
|
1367
1370
|
// src/util/import.ts
|
|
1368
1371
|
import { transformFile } from "@swc/core";
|
|
1369
|
-
import { dirname as dirname2, join as
|
|
1372
|
+
import { dirname as dirname2, join as join5 } from "path";
|
|
1370
1373
|
import { lstat, mkdir as mkdir3, writeFile as writeFile3 } from "fs/promises";
|
|
1371
1374
|
var resolveFileNameExtension = async (path) => {
|
|
1372
1375
|
const options = [
|
|
@@ -1407,14 +1410,14 @@ var importFile = async (path) => {
|
|
|
1407
1410
|
await Promise.all(matches?.map(async (match) => {
|
|
1408
1411
|
const parts = /('|")(\.[\/a-z0-9\_\-]+)('|")/ig.exec(match);
|
|
1409
1412
|
const from = parts[2];
|
|
1410
|
-
const file2 = await resolveFileNameExtension(
|
|
1413
|
+
const file2 = await resolveFileNameExtension(join5(path2, from));
|
|
1411
1414
|
const result = await load(file2);
|
|
1412
1415
|
code2 = code2.replace(match, result);
|
|
1413
1416
|
}));
|
|
1414
1417
|
return code2;
|
|
1415
1418
|
};
|
|
1416
1419
|
const code = await load(path);
|
|
1417
|
-
const outputFile =
|
|
1420
|
+
const outputFile = join5(outDir, "config.js");
|
|
1418
1421
|
await mkdir3(outDir, { recursive: true });
|
|
1419
1422
|
await writeFile3(outputFile, code);
|
|
1420
1423
|
return import(outputFile);
|
|
@@ -1423,7 +1426,7 @@ var importFile = async (path) => {
|
|
|
1423
1426
|
// src/config.ts
|
|
1424
1427
|
var importConfig = async (options) => {
|
|
1425
1428
|
debug("Import config file");
|
|
1426
|
-
const fileName =
|
|
1429
|
+
const fileName = join6(process.cwd(), options.configFile || "awsless.config.ts");
|
|
1427
1430
|
const module = await importFile(fileName);
|
|
1428
1431
|
const appConfig = typeof module.default === "function" ? await module.default({
|
|
1429
1432
|
profile: options.profile,
|
|
@@ -1891,7 +1894,7 @@ var assetBuilder = (assets) => {
|
|
|
1891
1894
|
};
|
|
1892
1895
|
|
|
1893
1896
|
// src/util/cleanup.ts
|
|
1894
|
-
import { mkdir as mkdir4, rm
|
|
1897
|
+
import { mkdir as mkdir4, rm } from "fs/promises";
|
|
1895
1898
|
var cleanUp = async () => {
|
|
1896
1899
|
debug("Clean up assembly & asset files");
|
|
1897
1900
|
const paths = [
|
|
@@ -1899,7 +1902,7 @@ var cleanUp = async () => {
|
|
|
1899
1902
|
assetDir,
|
|
1900
1903
|
cacheDir
|
|
1901
1904
|
];
|
|
1902
|
-
await Promise.all(paths.map((path) =>
|
|
1905
|
+
await Promise.all(paths.map((path) => rm(path, {
|
|
1903
1906
|
recursive: true,
|
|
1904
1907
|
force: true,
|
|
1905
1908
|
maxRetries: 2
|
|
@@ -1910,7 +1913,7 @@ var cleanUp = async () => {
|
|
|
1910
1913
|
};
|
|
1911
1914
|
|
|
1912
1915
|
// src/cli/command/build.ts
|
|
1913
|
-
var
|
|
1916
|
+
var build = (program2) => {
|
|
1914
1917
|
program2.command("build").argument("[stack...]", "Optionally filter stacks to build").description("Build your app").action(async (filters) => {
|
|
1915
1918
|
await layout(async (config2, write) => {
|
|
1916
1919
|
const { app, assets } = await toApp(config2, filters);
|
|
@@ -2506,7 +2509,7 @@ program.on("option:verbose", () => {
|
|
|
2506
2509
|
var commands2 = [
|
|
2507
2510
|
bootstrap,
|
|
2508
2511
|
status,
|
|
2509
|
-
|
|
2512
|
+
build,
|
|
2510
2513
|
deploy,
|
|
2511
2514
|
config
|
|
2512
2515
|
// diff,
|
package/dist/index.cjs
CHANGED
|
@@ -48,10 +48,9 @@ var getResourceProxy = (type) => {
|
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
50
|
};
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
var Store = getResourceProxy("STORE");
|
|
51
|
+
var Table = /* @__PURE__ */ getResourceProxy("TABLE");
|
|
52
|
+
var Queue = /* @__PURE__ */ getResourceProxy("QUEUE");
|
|
53
|
+
var Store = /* @__PURE__ */ getResourceProxy("STORE");
|
|
55
54
|
// Annotate the CommonJS export names for ESM import in node:
|
|
56
55
|
0 && (module.exports = {
|
|
57
56
|
Queue,
|
package/dist/index.js
CHANGED
|
@@ -18,10 +18,9 @@ var getResourceProxy = (type) => {
|
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var Store = getResourceProxy("STORE");
|
|
21
|
+
var Table = /* @__PURE__ */ getResourceProxy("TABLE");
|
|
22
|
+
var Queue = /* @__PURE__ */ getResourceProxy("QUEUE");
|
|
23
|
+
var Store = /* @__PURE__ */ getResourceProxy("STORE");
|
|
25
24
|
export {
|
|
26
25
|
Queue,
|
|
27
26
|
Store,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awsless/awsless",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -31,6 +31,8 @@
|
|
|
31
31
|
"@aws-sdk/client-sts": "^3.369.0",
|
|
32
32
|
"@aws-sdk/credential-providers": "^3.369.0",
|
|
33
33
|
"@graphql-tools/merge": "^9.0.0",
|
|
34
|
+
"@rollup/plugin-commonjs": "^24.0.1",
|
|
35
|
+
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
34
36
|
"@swc/core": "^1.3.70",
|
|
35
37
|
"@types/pretty-hrtime": "^1.0.1",
|
|
36
38
|
"aws-cdk-lib": "^2.87.0",
|
|
@@ -43,6 +45,8 @@
|
|
|
43
45
|
"graphql": "^16.7.1",
|
|
44
46
|
"jszip": "^3.10.1",
|
|
45
47
|
"pretty-hrtime": "^1.0.3",
|
|
48
|
+
"rollup": "^3.15.0",
|
|
49
|
+
"rollup-plugin-swc3": "^0.9.1",
|
|
46
50
|
"wrap-ansi": "^8.1.0",
|
|
47
51
|
"zod": "^3.21.4",
|
|
48
52
|
"@awsless/code": "^0.0.10"
|