@awsless/awsless 0.0.9 → 0.0.11
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 +95 -90
- package/dist/bin.js +79 -74
- package/dist/index.cjs +3 -4
- package/dist/index.js +3 -4
- package/package.json +6 -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,55 @@ 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_json = __toESM(require("@rollup/plugin-json"), 1);
|
|
526
|
+
var import_plugin_commonjs = __toESM(require("@rollup/plugin-commonjs"), 1);
|
|
527
|
+
var import_plugin_node_resolve = __toESM(require("@rollup/plugin-node-resolve"), 1);
|
|
528
|
+
var rollupBuild = async (input) => {
|
|
529
|
+
const bundle = await (0, import_rollup.rollup)({
|
|
530
|
+
input,
|
|
531
|
+
external: (importee) => {
|
|
532
|
+
return importee.startsWith("@aws-sdk") || importee.startsWith("aws-sdk");
|
|
533
|
+
},
|
|
534
|
+
onwarn: (error) => {
|
|
535
|
+
debugError(error.message);
|
|
536
|
+
},
|
|
537
|
+
treeshake: {
|
|
538
|
+
moduleSideEffects: (id) => input === id
|
|
539
|
+
},
|
|
540
|
+
plugins: [
|
|
541
|
+
(0, import_plugin_commonjs.default)({ sourceMap: true }),
|
|
542
|
+
(0, import_plugin_node_resolve.default)({
|
|
543
|
+
preferBuiltins: true
|
|
544
|
+
}),
|
|
545
|
+
(0, import_rollup_plugin_swc3.swc)({
|
|
546
|
+
minify: true,
|
|
547
|
+
jsc: { minify: { sourceMap: true } },
|
|
548
|
+
sourceMaps: true
|
|
549
|
+
}),
|
|
550
|
+
(0, import_plugin_json.default)()
|
|
551
|
+
]
|
|
552
|
+
});
|
|
553
|
+
const { output: [output] } = await bundle.generate({
|
|
554
|
+
format: "esm",
|
|
555
|
+
sourcemap: "hidden",
|
|
556
|
+
exports: "default"
|
|
557
|
+
});
|
|
558
|
+
const hash = (0, import_crypto.createHash)("sha1").update(output.code).digest("hex");
|
|
559
|
+
return {
|
|
560
|
+
handler: "index.default",
|
|
561
|
+
hash,
|
|
562
|
+
files: [{
|
|
563
|
+
name: "index.mjs",
|
|
564
|
+
code: output.code,
|
|
565
|
+
map: output.map?.toString()
|
|
566
|
+
}]
|
|
567
|
+
};
|
|
568
|
+
};
|
|
569
|
+
|
|
565
570
|
// src/plugins/function/index.ts
|
|
566
571
|
var FunctionSchema = import_zod9.z.union([
|
|
567
572
|
LocalFileSchema,
|
|
@@ -626,7 +631,7 @@ var toFunction = ({ config: config2, stack, assets }, id, fileOrProps) => {
|
|
|
626
631
|
resource: "function",
|
|
627
632
|
resourceName: id,
|
|
628
633
|
async build() {
|
|
629
|
-
const result = await
|
|
634
|
+
const result = await rollupBuild(props.file);
|
|
630
635
|
const bundle = await writeBuildFiles(config2, stack, id, result.files);
|
|
631
636
|
await writeBuildHash(config2, stack, id, result.hash);
|
|
632
637
|
const func = lambda.node.defaultChild;
|
|
@@ -941,7 +946,7 @@ var searchPlugin = definePlugin({
|
|
|
941
946
|
var import_zod21 = require("zod");
|
|
942
947
|
var import_aws_appsync = require("aws-cdk-lib/aws-appsync");
|
|
943
948
|
var import_merge = require("@graphql-tools/merge");
|
|
944
|
-
var
|
|
949
|
+
var import_promises4 = require("fs/promises");
|
|
945
950
|
|
|
946
951
|
// src/util/array.ts
|
|
947
952
|
var toArray = (value) => {
|
|
@@ -952,7 +957,7 @@ var toArray = (value) => {
|
|
|
952
957
|
};
|
|
953
958
|
|
|
954
959
|
// src/plugins/graphql/index.ts
|
|
955
|
-
var
|
|
960
|
+
var import_path6 = require("path");
|
|
956
961
|
var import_graphql = require("graphql");
|
|
957
962
|
var import_change_case2 = require("change-case");
|
|
958
963
|
|
|
@@ -997,7 +1002,7 @@ var graphqlPlugin = definePlugin({
|
|
|
997
1002
|
});
|
|
998
1003
|
});
|
|
999
1004
|
list3.forEach((id) => {
|
|
1000
|
-
const file = (0,
|
|
1005
|
+
const file = (0, import_path6.join)(assetDir, "graphql", config2.name, id, "schema.graphql");
|
|
1001
1006
|
const authorization = config2.defaults.graphql?.[id]?.authorization;
|
|
1002
1007
|
const authProps = {};
|
|
1003
1008
|
if (authorization) {
|
|
@@ -1028,13 +1033,13 @@ var graphqlPlugin = definePlugin({
|
|
|
1028
1033
|
await Promise.all(Object.values(config2.stacks).map(async (stackConfig) => {
|
|
1029
1034
|
const schemaFiles = toArray(stackConfig.graphql?.[id].schema || []);
|
|
1030
1035
|
await Promise.all(schemaFiles.map(async (schemaFile) => {
|
|
1031
|
-
const schema3 = await (0,
|
|
1036
|
+
const schema3 = await (0, import_promises4.readFile)(schemaFile, "utf8");
|
|
1032
1037
|
schemas.push(schema3);
|
|
1033
1038
|
}));
|
|
1034
1039
|
}));
|
|
1035
1040
|
const schema2 = (0, import_graphql.print)((0, import_merge.mergeTypeDefs)(schemas));
|
|
1036
|
-
await (0,
|
|
1037
|
-
await (0,
|
|
1041
|
+
await (0, import_promises4.mkdir)((0, import_path6.dirname)(file), { recursive: true });
|
|
1042
|
+
await (0, import_promises4.writeFile)(file, schema2);
|
|
1038
1043
|
new import_aws_appsync.CfnGraphQLSchema(stack, toId("schema", id), {
|
|
1039
1044
|
apiId: api.attrApiId,
|
|
1040
1045
|
definition: schema2
|
|
@@ -1316,7 +1321,7 @@ var footer = () => {
|
|
|
1316
1321
|
};
|
|
1317
1322
|
|
|
1318
1323
|
// src/config.ts
|
|
1319
|
-
var
|
|
1324
|
+
var import_path11 = require("path");
|
|
1320
1325
|
|
|
1321
1326
|
// src/util/account.ts
|
|
1322
1327
|
var import_client_sts = require("@aws-sdk/client-sts");
|
|
@@ -1389,8 +1394,8 @@ var AppSchema = import_zod25.z.object({
|
|
|
1389
1394
|
|
|
1390
1395
|
// src/util/import.ts
|
|
1391
1396
|
var import_core3 = require("@swc/core");
|
|
1392
|
-
var
|
|
1393
|
-
var
|
|
1397
|
+
var import_path9 = require("path");
|
|
1398
|
+
var import_promises5 = require("fs/promises");
|
|
1394
1399
|
var resolveFileNameExtension = async (path) => {
|
|
1395
1400
|
const options = [
|
|
1396
1401
|
"",
|
|
@@ -1403,7 +1408,7 @@ var resolveFileNameExtension = async (path) => {
|
|
|
1403
1408
|
const file = path + option;
|
|
1404
1409
|
let stat;
|
|
1405
1410
|
try {
|
|
1406
|
-
stat = await (0,
|
|
1411
|
+
stat = await (0, import_promises5.lstat)(file);
|
|
1407
1412
|
} catch (error) {
|
|
1408
1413
|
continue;
|
|
1409
1414
|
}
|
|
@@ -1414,14 +1419,14 @@ var resolveFileNameExtension = async (path) => {
|
|
|
1414
1419
|
throw new Error(`Failed to load file: ${path}`);
|
|
1415
1420
|
};
|
|
1416
1421
|
var resolveDir = (path) => {
|
|
1417
|
-
return (0,
|
|
1422
|
+
return (0, import_path9.dirname)(path).replace(rootDir + "/", "");
|
|
1418
1423
|
};
|
|
1419
1424
|
var importFile = async (path) => {
|
|
1420
1425
|
const load = async (file) => {
|
|
1421
1426
|
let { code: code2 } = await (0, import_core3.transformFile)(file, {
|
|
1422
1427
|
isModule: true
|
|
1423
1428
|
});
|
|
1424
|
-
const path2 = (0,
|
|
1429
|
+
const path2 = (0, import_path9.dirname)(file);
|
|
1425
1430
|
const dir = resolveDir(file);
|
|
1426
1431
|
code2 = code2.replaceAll("__dirname", `"${dir}"`);
|
|
1427
1432
|
const matches = code2.match(/import\s*{\s*[a-z0-9\_]+\s*}\s*from\s*('|")(\.[\/a-z0-9\_\-]+)('|");?/ig);
|
|
@@ -1430,23 +1435,23 @@ var importFile = async (path) => {
|
|
|
1430
1435
|
await Promise.all(matches?.map(async (match) => {
|
|
1431
1436
|
const parts = /('|")(\.[\/a-z0-9\_\-]+)('|")/ig.exec(match);
|
|
1432
1437
|
const from = parts[2];
|
|
1433
|
-
const file2 = await resolveFileNameExtension((0,
|
|
1438
|
+
const file2 = await resolveFileNameExtension((0, import_path9.join)(path2, from));
|
|
1434
1439
|
const result = await load(file2);
|
|
1435
1440
|
code2 = code2.replace(match, result);
|
|
1436
1441
|
}));
|
|
1437
1442
|
return code2;
|
|
1438
1443
|
};
|
|
1439
1444
|
const code = await load(path);
|
|
1440
|
-
const outputFile = (0,
|
|
1441
|
-
await (0,
|
|
1442
|
-
await (0,
|
|
1445
|
+
const outputFile = (0, import_path9.join)(outDir, "config.js");
|
|
1446
|
+
await (0, import_promises5.mkdir)(outDir, { recursive: true });
|
|
1447
|
+
await (0, import_promises5.writeFile)(outputFile, code);
|
|
1443
1448
|
return import(outputFile);
|
|
1444
1449
|
};
|
|
1445
1450
|
|
|
1446
1451
|
// src/config.ts
|
|
1447
1452
|
var importConfig = async (options) => {
|
|
1448
1453
|
debug("Import config file");
|
|
1449
|
-
const fileName = (0,
|
|
1454
|
+
const fileName = (0, import_path11.join)(process.cwd(), options.configFile || "awsless.config.ts");
|
|
1450
1455
|
const module2 = await importFile(fileName);
|
|
1451
1456
|
const appConfig = typeof module2.default === "function" ? await module2.default({
|
|
1452
1457
|
profile: options.profile,
|
|
@@ -1914,7 +1919,7 @@ var assetBuilder = (assets) => {
|
|
|
1914
1919
|
};
|
|
1915
1920
|
|
|
1916
1921
|
// src/util/cleanup.ts
|
|
1917
|
-
var
|
|
1922
|
+
var import_promises6 = require("fs/promises");
|
|
1918
1923
|
var cleanUp = async () => {
|
|
1919
1924
|
debug("Clean up assembly & asset files");
|
|
1920
1925
|
const paths = [
|
|
@@ -1922,18 +1927,18 @@ var cleanUp = async () => {
|
|
|
1922
1927
|
assetDir,
|
|
1923
1928
|
cacheDir
|
|
1924
1929
|
];
|
|
1925
|
-
await Promise.all(paths.map((path) => (0,
|
|
1930
|
+
await Promise.all(paths.map((path) => (0, import_promises6.rm)(path, {
|
|
1926
1931
|
recursive: true,
|
|
1927
1932
|
force: true,
|
|
1928
1933
|
maxRetries: 2
|
|
1929
1934
|
})));
|
|
1930
|
-
await Promise.all(paths.map((path) => (0,
|
|
1935
|
+
await Promise.all(paths.map((path) => (0, import_promises6.mkdir)(path, {
|
|
1931
1936
|
recursive: true
|
|
1932
1937
|
})));
|
|
1933
1938
|
};
|
|
1934
1939
|
|
|
1935
1940
|
// src/cli/command/build.ts
|
|
1936
|
-
var
|
|
1941
|
+
var build = (program2) => {
|
|
1937
1942
|
program2.command("build").argument("[stack...]", "Optionally filter stacks to build").description("Build your app").action(async (filters) => {
|
|
1938
1943
|
await layout(async (config2, write) => {
|
|
1939
1944
|
const { app, assets } = await toApp(config2, filters);
|
|
@@ -2529,7 +2534,7 @@ program.on("option:verbose", () => {
|
|
|
2529
2534
|
var commands2 = [
|
|
2530
2535
|
bootstrap,
|
|
2531
2536
|
status,
|
|
2532
|
-
|
|
2537
|
+
build,
|
|
2533
2538
|
deploy,
|
|
2534
2539
|
config
|
|
2535
2540
|
// 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,55 @@ 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 json from "@rollup/plugin-json";
|
|
503
|
+
import commonjs from "@rollup/plugin-commonjs";
|
|
504
|
+
import nodeResolve from "@rollup/plugin-node-resolve";
|
|
505
|
+
var rollupBuild = async (input) => {
|
|
506
|
+
const bundle = await rollup({
|
|
507
|
+
input,
|
|
508
|
+
external: (importee) => {
|
|
509
|
+
return importee.startsWith("@aws-sdk") || importee.startsWith("aws-sdk");
|
|
510
|
+
},
|
|
511
|
+
onwarn: (error) => {
|
|
512
|
+
debugError(error.message);
|
|
513
|
+
},
|
|
514
|
+
treeshake: {
|
|
515
|
+
moduleSideEffects: (id) => input === id
|
|
516
|
+
},
|
|
517
|
+
plugins: [
|
|
518
|
+
commonjs({ sourceMap: true }),
|
|
519
|
+
nodeResolve({
|
|
520
|
+
preferBuiltins: true
|
|
521
|
+
}),
|
|
522
|
+
swc({
|
|
523
|
+
minify: true,
|
|
524
|
+
jsc: { minify: { sourceMap: true } },
|
|
525
|
+
sourceMaps: true
|
|
526
|
+
}),
|
|
527
|
+
json()
|
|
528
|
+
]
|
|
529
|
+
});
|
|
530
|
+
const { output: [output] } = await bundle.generate({
|
|
531
|
+
format: "esm",
|
|
532
|
+
sourcemap: "hidden",
|
|
533
|
+
exports: "default"
|
|
534
|
+
});
|
|
535
|
+
const hash = createHash("sha1").update(output.code).digest("hex");
|
|
536
|
+
return {
|
|
537
|
+
handler: "index.default",
|
|
538
|
+
hash,
|
|
539
|
+
files: [{
|
|
540
|
+
name: "index.mjs",
|
|
541
|
+
code: output.code,
|
|
542
|
+
map: output.map?.toString()
|
|
543
|
+
}]
|
|
544
|
+
};
|
|
545
|
+
};
|
|
546
|
+
|
|
542
547
|
// src/plugins/function/index.ts
|
|
543
548
|
var FunctionSchema = z9.union([
|
|
544
549
|
LocalFileSchema,
|
|
@@ -603,7 +608,7 @@ var toFunction = ({ config: config2, stack, assets }, id, fileOrProps) => {
|
|
|
603
608
|
resource: "function",
|
|
604
609
|
resourceName: id,
|
|
605
610
|
async build() {
|
|
606
|
-
const result = await
|
|
611
|
+
const result = await rollupBuild(props.file);
|
|
607
612
|
const bundle = await writeBuildFiles(config2, stack, id, result.files);
|
|
608
613
|
await writeBuildHash(config2, stack, id, result.hash);
|
|
609
614
|
const func = lambda.node.defaultChild;
|
|
@@ -918,7 +923,7 @@ var searchPlugin = definePlugin({
|
|
|
918
923
|
import { z as z21 } from "zod";
|
|
919
924
|
import { AuthorizationType, CfnGraphQLApi, CfnGraphQLSchema, GraphqlApi, MappingTemplate } from "aws-cdk-lib/aws-appsync";
|
|
920
925
|
import { mergeTypeDefs } from "@graphql-tools/merge";
|
|
921
|
-
import { mkdir as mkdir2, readFile as
|
|
926
|
+
import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
|
|
922
927
|
|
|
923
928
|
// src/util/array.ts
|
|
924
929
|
var toArray = (value) => {
|
|
@@ -929,7 +934,7 @@ var toArray = (value) => {
|
|
|
929
934
|
};
|
|
930
935
|
|
|
931
936
|
// src/plugins/graphql/index.ts
|
|
932
|
-
import { dirname, join as
|
|
937
|
+
import { dirname, join as join4 } from "path";
|
|
933
938
|
import { print } from "graphql";
|
|
934
939
|
import { paramCase as paramCase2 } from "change-case";
|
|
935
940
|
|
|
@@ -974,7 +979,7 @@ var graphqlPlugin = definePlugin({
|
|
|
974
979
|
});
|
|
975
980
|
});
|
|
976
981
|
list3.forEach((id) => {
|
|
977
|
-
const file =
|
|
982
|
+
const file = join4(assetDir, "graphql", config2.name, id, "schema.graphql");
|
|
978
983
|
const authorization = config2.defaults.graphql?.[id]?.authorization;
|
|
979
984
|
const authProps = {};
|
|
980
985
|
if (authorization) {
|
|
@@ -1005,7 +1010,7 @@ var graphqlPlugin = definePlugin({
|
|
|
1005
1010
|
await Promise.all(Object.values(config2.stacks).map(async (stackConfig) => {
|
|
1006
1011
|
const schemaFiles = toArray(stackConfig.graphql?.[id].schema || []);
|
|
1007
1012
|
await Promise.all(schemaFiles.map(async (schemaFile) => {
|
|
1008
|
-
const schema3 = await
|
|
1013
|
+
const schema3 = await readFile2(schemaFile, "utf8");
|
|
1009
1014
|
schemas.push(schema3);
|
|
1010
1015
|
}));
|
|
1011
1016
|
}));
|
|
@@ -1293,7 +1298,7 @@ var footer = () => {
|
|
|
1293
1298
|
};
|
|
1294
1299
|
|
|
1295
1300
|
// src/config.ts
|
|
1296
|
-
import { join as
|
|
1301
|
+
import { join as join6 } from "path";
|
|
1297
1302
|
|
|
1298
1303
|
// src/util/account.ts
|
|
1299
1304
|
import { STSClient, GetCallerIdentityCommand } from "@aws-sdk/client-sts";
|
|
@@ -1366,7 +1371,7 @@ var AppSchema = z25.object({
|
|
|
1366
1371
|
|
|
1367
1372
|
// src/util/import.ts
|
|
1368
1373
|
import { transformFile } from "@swc/core";
|
|
1369
|
-
import { dirname as dirname2, join as
|
|
1374
|
+
import { dirname as dirname2, join as join5 } from "path";
|
|
1370
1375
|
import { lstat, mkdir as mkdir3, writeFile as writeFile3 } from "fs/promises";
|
|
1371
1376
|
var resolveFileNameExtension = async (path) => {
|
|
1372
1377
|
const options = [
|
|
@@ -1407,14 +1412,14 @@ var importFile = async (path) => {
|
|
|
1407
1412
|
await Promise.all(matches?.map(async (match) => {
|
|
1408
1413
|
const parts = /('|")(\.[\/a-z0-9\_\-]+)('|")/ig.exec(match);
|
|
1409
1414
|
const from = parts[2];
|
|
1410
|
-
const file2 = await resolveFileNameExtension(
|
|
1415
|
+
const file2 = await resolveFileNameExtension(join5(path2, from));
|
|
1411
1416
|
const result = await load(file2);
|
|
1412
1417
|
code2 = code2.replace(match, result);
|
|
1413
1418
|
}));
|
|
1414
1419
|
return code2;
|
|
1415
1420
|
};
|
|
1416
1421
|
const code = await load(path);
|
|
1417
|
-
const outputFile =
|
|
1422
|
+
const outputFile = join5(outDir, "config.js");
|
|
1418
1423
|
await mkdir3(outDir, { recursive: true });
|
|
1419
1424
|
await writeFile3(outputFile, code);
|
|
1420
1425
|
return import(outputFile);
|
|
@@ -1423,7 +1428,7 @@ var importFile = async (path) => {
|
|
|
1423
1428
|
// src/config.ts
|
|
1424
1429
|
var importConfig = async (options) => {
|
|
1425
1430
|
debug("Import config file");
|
|
1426
|
-
const fileName =
|
|
1431
|
+
const fileName = join6(process.cwd(), options.configFile || "awsless.config.ts");
|
|
1427
1432
|
const module = await importFile(fileName);
|
|
1428
1433
|
const appConfig = typeof module.default === "function" ? await module.default({
|
|
1429
1434
|
profile: options.profile,
|
|
@@ -1891,7 +1896,7 @@ var assetBuilder = (assets) => {
|
|
|
1891
1896
|
};
|
|
1892
1897
|
|
|
1893
1898
|
// src/util/cleanup.ts
|
|
1894
|
-
import { mkdir as mkdir4, rm
|
|
1899
|
+
import { mkdir as mkdir4, rm } from "fs/promises";
|
|
1895
1900
|
var cleanUp = async () => {
|
|
1896
1901
|
debug("Clean up assembly & asset files");
|
|
1897
1902
|
const paths = [
|
|
@@ -1899,7 +1904,7 @@ var cleanUp = async () => {
|
|
|
1899
1904
|
assetDir,
|
|
1900
1905
|
cacheDir
|
|
1901
1906
|
];
|
|
1902
|
-
await Promise.all(paths.map((path) =>
|
|
1907
|
+
await Promise.all(paths.map((path) => rm(path, {
|
|
1903
1908
|
recursive: true,
|
|
1904
1909
|
force: true,
|
|
1905
1910
|
maxRetries: 2
|
|
@@ -1910,7 +1915,7 @@ var cleanUp = async () => {
|
|
|
1910
1915
|
};
|
|
1911
1916
|
|
|
1912
1917
|
// src/cli/command/build.ts
|
|
1913
|
-
var
|
|
1918
|
+
var build = (program2) => {
|
|
1914
1919
|
program2.command("build").argument("[stack...]", "Optionally filter stacks to build").description("Build your app").action(async (filters) => {
|
|
1915
1920
|
await layout(async (config2, write) => {
|
|
1916
1921
|
const { app, assets } = await toApp(config2, filters);
|
|
@@ -2506,7 +2511,7 @@ program.on("option:verbose", () => {
|
|
|
2506
2511
|
var commands2 = [
|
|
2507
2512
|
bootstrap,
|
|
2508
2513
|
status,
|
|
2509
|
-
|
|
2514
|
+
build,
|
|
2510
2515
|
deploy,
|
|
2511
2516
|
config
|
|
2512
2517
|
// 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.11",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -31,6 +31,9 @@
|
|
|
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-json": "^6.0.0",
|
|
36
|
+
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
34
37
|
"@swc/core": "^1.3.70",
|
|
35
38
|
"@types/pretty-hrtime": "^1.0.1",
|
|
36
39
|
"aws-cdk-lib": "^2.87.0",
|
|
@@ -43,6 +46,8 @@
|
|
|
43
46
|
"graphql": "^16.7.1",
|
|
44
47
|
"jszip": "^3.10.1",
|
|
45
48
|
"pretty-hrtime": "^1.0.3",
|
|
49
|
+
"rollup": "^3.15.0",
|
|
50
|
+
"rollup-plugin-swc3": "^0.9.1",
|
|
46
51
|
"wrap-ansi": "^8.1.0",
|
|
47
52
|
"zod": "^3.21.4",
|
|
48
53
|
"@awsless/code": "^0.0.10"
|