@awsless/awsless 0.0.174 → 0.0.176

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.
Files changed (2) hide show
  1. package/dist/bin.js +167 -86
  2. package/package.json +4 -4
package/dist/bin.js CHANGED
@@ -1062,8 +1062,8 @@ var Cancelled = class extends Error {
1062
1062
  // src/config/load/read.ts
1063
1063
  var readConfig = async (file) => {
1064
1064
  try {
1065
- const json3 = await readFile(file, "utf8");
1066
- const data = JSON5.parse(json3);
1065
+ const json4 = await readFile(file, "utf8");
1066
+ const data = JSON5.parse(json4);
1067
1067
  return data;
1068
1068
  } catch (error) {
1069
1069
  if (error instanceof Error) {
@@ -2479,7 +2479,7 @@ import { paramCase as paramCase5 } from "change-case";
2479
2479
  import { mergeTypeDefs } from "@graphql-tools/merge";
2480
2480
  import { generate } from "@awsless/graphql";
2481
2481
  import { buildSchema, print } from "graphql";
2482
- import { readFile as readFile4 } from "fs/promises";
2482
+ import { readFile as readFile5 } from "fs/promises";
2483
2483
  import { Asset as Asset2, Node as Node6, aws as aws6 } from "@awsless/formation";
2484
2484
 
2485
2485
  // src/feature/domain/util.ts
@@ -2500,6 +2500,134 @@ var formatFullDomainName = (config2, id, subDomain) => {
2500
2500
  return domain;
2501
2501
  };
2502
2502
 
2503
+ // src/build/fingerprint.ts
2504
+ import { createHash as createHash3 } from "crypto";
2505
+ import { readFile as readFile4, readdir as readdir2, stat as stat4 } from "fs/promises";
2506
+ import { basename as basename4, dirname as dirname6, extname as extname3, join as join7 } from "path";
2507
+ import parseStaticImports2 from "parse-static-imports";
2508
+ var extensions2 = ["js", "mjs", "jsx", "ts", "mts", "tsx"];
2509
+ var generateFileHashes2 = async (file, hashes) => {
2510
+ if (hashes.has(file)) {
2511
+ return;
2512
+ }
2513
+ const code = await readModuleFile2(file);
2514
+ const deps = await findDependencies2(file, code);
2515
+ const hash = createHash3("sha1").update(code).digest();
2516
+ hashes.set(file, hash);
2517
+ for (const dep of deps) {
2518
+ if (dep.startsWith("/")) {
2519
+ await generateFileHashes2(dep, hashes);
2520
+ }
2521
+ }
2522
+ };
2523
+ var fingerprintFromFile2 = async (file) => {
2524
+ const hashes = /* @__PURE__ */ new Map();
2525
+ await generateFileHashes2(file, hashes);
2526
+ const merge2 = Buffer.concat(Array.from(hashes.values()).sort());
2527
+ return createHash3("sha1").update(merge2).digest("hex");
2528
+ };
2529
+ var fingerprintFromDirectory = async (dir) => {
2530
+ const hashes = /* @__PURE__ */ new Map();
2531
+ const files = await readdir2(dir, { recursive: true });
2532
+ for (const file of files) {
2533
+ if (extensions2.includes(extname3(file).substring(1))) {
2534
+ await generateFileHashes2(join7(dir, file), hashes);
2535
+ }
2536
+ }
2537
+ const merge2 = Buffer.concat(Array.from(hashes.values()).sort());
2538
+ return createHash3("sha1").update(merge2).digest("hex");
2539
+ };
2540
+ var readModuleFile2 = (file) => {
2541
+ if (file.endsWith(".js")) {
2542
+ return readFiles2([file, file.substring(0, file.length - 3) + ".ts"]);
2543
+ }
2544
+ if (!basename4(file).includes(".")) {
2545
+ return readFiles2([
2546
+ file,
2547
+ ...extensions2.map((exp) => `${file}.${exp}`),
2548
+ ...extensions2.map((exp) => join7(file, `/index.${exp}`))
2549
+ ]);
2550
+ }
2551
+ return readFile4(file, "utf8");
2552
+ };
2553
+ var readFiles2 = async (files) => {
2554
+ for (const file of files) {
2555
+ try {
2556
+ const s = await stat4(file);
2557
+ if (s.isFile()) {
2558
+ return readFile4(file, "utf8");
2559
+ }
2560
+ } catch (_) {
2561
+ continue;
2562
+ }
2563
+ }
2564
+ throw new Error(`No such file: ${files.join(", ")}`);
2565
+ };
2566
+ var findDependencies2 = async (file, code) => {
2567
+ const imports = await parseStaticImports2(code);
2568
+ return imports.map((entry) => entry.moduleName).filter(Boolean).map((value) => value?.startsWith(".") ? join7(dirname6(file), value) : value);
2569
+ };
2570
+
2571
+ // src/feature/graphql/build/typescript/resolver.ts
2572
+ import { rollup as rollup2 } from "rollup";
2573
+ import { swc as swc2, minify as swcMinify2 } from "rollup-plugin-swc3";
2574
+ import json2 from "@rollup/plugin-json";
2575
+ import commonjs2 from "@rollup/plugin-commonjs";
2576
+ import nodeResolve2 from "@rollup/plugin-node-resolve";
2577
+ import { dirname as dirname7 } from "path";
2578
+ var buildTypeScriptResolver = async (input, { minify = true } = {}) => {
2579
+ const bundle = await rollup2({
2580
+ input,
2581
+ external: (importee) => {
2582
+ return importee.startsWith("@aws-sdk") || importee.startsWith("aws-sdk") || importee.startsWith("@aws-appsync/utils");
2583
+ },
2584
+ onwarn: (error) => {
2585
+ debugError(error.message);
2586
+ },
2587
+ treeshake: {
2588
+ moduleSideEffects: (id) => input === id
2589
+ },
2590
+ plugins: [
2591
+ // @ts-ignore
2592
+ commonjs2({ sourceMap: true }),
2593
+ // @ts-ignore
2594
+ nodeResolve2({ preferBuiltins: true }),
2595
+ swc2({
2596
+ // minify,
2597
+ // module: true,
2598
+ jsc: {
2599
+ baseUrl: dirname7(input),
2600
+ minify: { sourceMap: true }
2601
+ },
2602
+ sourceMaps: true
2603
+ }),
2604
+ minify ? swcMinify2({
2605
+ module: true,
2606
+ sourceMap: true,
2607
+ compress: true
2608
+ }) : void 0,
2609
+ // @ts-ignore
2610
+ json2()
2611
+ ]
2612
+ });
2613
+ const result = await bundle.generate({
2614
+ format: "esm",
2615
+ sourcemap: "hidden",
2616
+ exports: "auto",
2617
+ manualChunks: {},
2618
+ entryFileNames: `index.mjs`,
2619
+ chunkFileNames: `[name].mjs`
2620
+ });
2621
+ let code;
2622
+ for (const item of result.output) {
2623
+ if (item.type !== "chunk") {
2624
+ continue;
2625
+ }
2626
+ code = item.code;
2627
+ }
2628
+ return Buffer.from(code, "utf8");
2629
+ };
2630
+
2503
2631
  // src/feature/graphql/index.ts
2504
2632
  var defaultResolver = `
2505
2633
  export function request(ctx) {
@@ -2545,7 +2673,7 @@ var graphqlFeature = defineFeature({
2545
2673
  for (const [id, files] of apis) {
2546
2674
  const sources = await Promise.all(
2547
2675
  files.map((file) => {
2548
- return readFile4(file, "utf8");
2676
+ return readFile5(file, "utf8");
2549
2677
  })
2550
2678
  );
2551
2679
  if (sources.length) {
@@ -2609,8 +2737,24 @@ var graphqlFeature = defineFeature({
2609
2737
  }
2610
2738
  }
2611
2739
  });
2612
- ctx.base.export(`graphql-${id}-id`, api.id);
2613
2740
  group.add(api);
2741
+ ctx.base.export(`graphql-${id}-id`, api.id);
2742
+ if (props.resolver) {
2743
+ ctx.registerBuild("graphql-resolver", id, async (build3) => {
2744
+ const resolver = props.resolver;
2745
+ const version = await fingerprintFromFile2(resolver);
2746
+ return build3(version, async (write) => {
2747
+ const file = await buildTypeScriptResolver(resolver);
2748
+ if (!file) {
2749
+ throw new FileError(resolver, `Failed to build a graphql resolver.`);
2750
+ }
2751
+ await write("resolver.js", file);
2752
+ return {
2753
+ size: formatByteSize(file.byteLength)
2754
+ };
2755
+ });
2756
+ });
2757
+ }
2614
2758
  if (props.domain) {
2615
2759
  const domainName = formatFullDomainName(ctx.appConfig, props.domain, props.subDomain);
2616
2760
  const domainGroup = new Node6("domain", domainName);
@@ -2707,9 +2851,8 @@ var graphqlFeature = defineFeature({
2707
2851
  let code = Asset2.fromString(defaultResolver);
2708
2852
  if ("resolver" in props2 && props2.resolver) {
2709
2853
  code = Asset2.fromFile(props2.resolver);
2710
- }
2711
- if (defaultProps.resolver) {
2712
- code = Asset2.fromString(defaultProps.resolver);
2854
+ } else if (defaultProps.resolver) {
2855
+ code = Asset2.fromFile(getBuildPath("graphql-resolver", id, "resolver.js"));
2713
2856
  }
2714
2857
  const config2 = new aws6.appsync.FunctionConfiguration("config", {
2715
2858
  apiId: api.id,
@@ -3292,9 +3435,9 @@ import { camelCase as camelCase5 } from "change-case";
3292
3435
  import { relative as relative3 } from "path";
3293
3436
 
3294
3437
  // src/util/id.ts
3295
- import { createHash as createHash3 } from "crypto";
3438
+ import { createHash as createHash4 } from "crypto";
3296
3439
  var shortId = (ns) => {
3297
- return createHash3("md5").update(ns).digest("hex").substring(0, 10);
3440
+ return createHash4("md5").update(ns).digest("hex").substring(0, 10);
3298
3441
  };
3299
3442
 
3300
3443
  // src/feature/http/index.ts
@@ -3528,11 +3671,11 @@ var searchFeature = defineFeature({
3528
3671
  import { Asset as Asset3, Node as Node17, aws as aws17 } from "@awsless/formation";
3529
3672
  import { days as days3, seconds as seconds3 } from "@awsless/duration";
3530
3673
  import { glob as glob2 } from "glob";
3531
- import { join as join7 } from "path";
3674
+ import { join as join8 } from "path";
3532
3675
 
3533
3676
  // src/feature/site/util.ts
3534
3677
  import { lookup, contentType } from "mime-types";
3535
- import { extname as extname3 } from "path";
3678
+ import { extname as extname4 } from "path";
3536
3679
  var getCacheControl = (file) => {
3537
3680
  switch (lookup(file)) {
3538
3681
  case false:
@@ -3547,7 +3690,7 @@ var getCacheControl = (file) => {
3547
3690
  }
3548
3691
  };
3549
3692
  var getContentType = (file) => {
3550
- return contentType(extname3(file)) || "text/html; charset=utf-8";
3693
+ return contentType(extname4(file)) || "text/html; charset=utf-8";
3551
3694
  };
3552
3695
 
3553
3696
  // src/feature/site/index.ts
@@ -3622,7 +3765,7 @@ var siteFeature = defineFeature({
3622
3765
  const object = new aws17.s3.BucketObject(file, {
3623
3766
  bucket: bucket.name,
3624
3767
  key: file,
3625
- body: Asset3.fromFile(join7(props.static, file)),
3768
+ body: Asset3.fromFile(join8(props.static, file)),
3626
3769
  cacheControl: getCacheControl(file),
3627
3770
  contentType: getContentType(file)
3628
3771
  });
@@ -4097,68 +4240,6 @@ import { run } from "promise-dag";
4097
4240
  import { join as join9 } from "path";
4098
4241
  import { mkdir as mkdir2, readFile as readFile6, writeFile as writeFile2 } from "fs/promises";
4099
4242
 
4100
- // src/build/fingerprint.ts
4101
- import { createHash as createHash4 } from "crypto";
4102
- import { readFile as readFile5, readdir as readdir2, stat as stat4 } from "fs/promises";
4103
- import { basename as basename4, dirname as dirname6, extname as extname4, join as join8 } from "path";
4104
- import parseStaticImports2 from "parse-static-imports";
4105
- var extensions2 = ["js", "mjs", "jsx", "ts", "mts", "tsx"];
4106
- var generateFileHashes2 = async (file, hashes) => {
4107
- if (hashes.has(file)) {
4108
- return;
4109
- }
4110
- const code = await readModuleFile2(file);
4111
- const deps = await findDependencies2(file, code);
4112
- const hash = createHash4("sha1").update(code).digest();
4113
- hashes.set(file, hash);
4114
- for (const dep of deps) {
4115
- if (dep.startsWith("/")) {
4116
- await generateFileHashes2(dep, hashes);
4117
- }
4118
- }
4119
- };
4120
- var fingerprintFromDirectory = async (dir) => {
4121
- const hashes = /* @__PURE__ */ new Map();
4122
- const files = await readdir2(dir, { recursive: true });
4123
- for (const file of files) {
4124
- if (extensions2.includes(extname4(file).substring(1))) {
4125
- await generateFileHashes2(join8(dir, file), hashes);
4126
- }
4127
- }
4128
- const merge2 = Buffer.concat(Array.from(hashes.values()).sort());
4129
- return createHash4("sha1").update(merge2).digest("hex");
4130
- };
4131
- var readModuleFile2 = (file) => {
4132
- if (file.endsWith(".js")) {
4133
- return readFiles2([file, file.substring(0, file.length - 3) + ".ts"]);
4134
- }
4135
- if (!basename4(file).includes(".")) {
4136
- return readFiles2([
4137
- file,
4138
- ...extensions2.map((exp) => `${file}.${exp}`),
4139
- ...extensions2.map((exp) => join8(file, `/index.${exp}`))
4140
- ]);
4141
- }
4142
- return readFile5(file, "utf8");
4143
- };
4144
- var readFiles2 = async (files) => {
4145
- for (const file of files) {
4146
- try {
4147
- const s = await stat4(file);
4148
- if (s.isFile()) {
4149
- return readFile5(file, "utf8");
4150
- }
4151
- } catch (_) {
4152
- continue;
4153
- }
4154
- }
4155
- throw new Error(`No such file: ${files.join(", ")}`);
4156
- };
4157
- var findDependencies2 = async (file, code) => {
4158
- const imports = await parseStaticImports2(code);
4159
- return imports.map((entry) => entry.moduleName).filter(Boolean).map((value) => value?.startsWith(".") ? join8(dirname6(file), value) : value);
4160
- };
4161
-
4162
4243
  // src/test/reporter.ts
4163
4244
  import { getSuites, getTests } from "@vitest/runner/utils";
4164
4245
  var CustomReporter = class {
@@ -4239,12 +4320,12 @@ var CustomReporter = class {
4239
4320
  };
4240
4321
 
4241
4322
  // src/test/start.ts
4242
- import { swc as swc2 } from "rollup-plugin-swc3";
4323
+ import { swc as swc3 } from "rollup-plugin-swc3";
4243
4324
  import { configDefaults } from "vitest/config";
4244
4325
  import { startVitest } from "vitest/node";
4245
- import commonjs2 from "@rollup/plugin-commonjs";
4246
- import nodeResolve2 from "@rollup/plugin-node-resolve";
4247
- import json2 from "@rollup/plugin-json";
4326
+ import commonjs3 from "@rollup/plugin-commonjs";
4327
+ import nodeResolve3 from "@rollup/plugin-node-resolve";
4328
+ import json3 from "@rollup/plugin-json";
4248
4329
  var startTest = async (props) => {
4249
4330
  const result = await startVitest(
4250
4331
  "test",
@@ -4266,10 +4347,10 @@ var startTest = async (props) => {
4266
4347
  {
4267
4348
  plugins: [
4268
4349
  // @ts-ignore
4269
- commonjs2({ sourceMap: true }),
4350
+ commonjs3({ sourceMap: true }),
4270
4351
  // @ts-ignore
4271
- nodeResolve2({ preferBuiltins: true }),
4272
- swc2({
4352
+ nodeResolve3({ preferBuiltins: true }),
4353
+ swc3({
4273
4354
  jsc: {
4274
4355
  // baseUrl: dirname(input),
4275
4356
  minify: { sourceMap: true }
@@ -4277,7 +4358,7 @@ var startTest = async (props) => {
4277
4358
  sourceMaps: true
4278
4359
  }),
4279
4360
  // @ts-ignore
4280
- json2()
4361
+ json3()
4281
4362
  ]
4282
4363
  }
4283
4364
  );
@@ -4549,7 +4630,7 @@ import { log as log8 } from "@clack/prompts";
4549
4630
 
4550
4631
  // src/type-gen/generate.ts
4551
4632
  import { mkdir as mkdir3, writeFile as writeFile3 } from "fs/promises";
4552
- import { dirname as dirname7, join as join10, relative as relative4 } from "path";
4633
+ import { dirname as dirname8, join as join10, relative as relative4 } from "path";
4553
4634
  var generateTypes = async (props) => {
4554
4635
  const files = [];
4555
4636
  await Promise.all(
@@ -4563,7 +4644,7 @@ var generateTypes = async (props) => {
4563
4644
  if (include) {
4564
4645
  files.push(relative4(directories.root, path));
4565
4646
  }
4566
- await mkdir3(dirname7(path), { recursive: true });
4647
+ await mkdir3(dirname8(path), { recursive: true });
4567
4648
  await writeFile3(path, code);
4568
4649
  }
4569
4650
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/awsless",
3
- "version": "0.0.174",
3
+ "version": "0.0.176",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -29,9 +29,9 @@
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@awsless/lambda": "^0.0.18",
32
+ "@awsless/sns": "^0.0.7",
32
33
  "@awsless/redis": "^0.0.12",
33
34
  "@awsless/s3": "^0.0.10",
34
- "@awsless/sns": "^0.0.7",
35
35
  "@awsless/sqs": "^0.0.7",
36
36
  "@awsless/ssm": "^0.0.7",
37
37
  "@awsless/weak-cache": "^0.0.1",
@@ -97,10 +97,10 @@
97
97
  "zod": "^3.21.4",
98
98
  "zod-to-json-schema": "^3.22.3",
99
99
  "@awsless/duration": "^0.0.1",
100
- "@awsless/formation": "^0.0.5",
100
+ "@awsless/graphql": "^0.0.9",
101
101
  "@awsless/size": "^0.0.1",
102
+ "@awsless/formation": "^0.0.5",
102
103
  "@awsless/validate": "^0.0.13",
103
- "@awsless/graphql": "^0.0.9",
104
104
  "@awsless/code": "^0.0.10"
105
105
  },
106
106
  "scripts": {