@awsless/awsless 0.0.7 → 0.0.8

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 CHANGED
@@ -380,45 +380,69 @@ var SizeSchema = import_zod7.z.custom((value) => {
380
380
  }, "Invalid size").transform(toSize);
381
381
 
382
382
  // src/plugins/function/util/build-worker.ts
383
- var import_core3 = require("@swc/core");
384
- var import_crypto = require("crypto");
383
+ var import_worker_threads = require("worker_threads");
384
+ var cjs = typeof require !== "undefined";
385
+ var importESM = `
386
+ import { bundle } from "@awsless/code";
387
+ import { createHash } from "crypto";
388
+ import { parentPort, workerData } from "worker_threads";
389
+ `;
390
+ var importCJS = `
391
+ const { bundle } = require("@awsless/code");
392
+ const { createHash } = require("crypto");
393
+ const { parentPort, workerData } = require("worker_threads");
394
+ `;
395
+ var workerCode = `
396
+ ${cjs ? importCJS : importESM}
397
+
398
+ const build = async (file) => {
399
+ const { code, map } = await bundle(file, {
400
+ format: 'esm',
401
+ sourceMap: true,
402
+ minimize: true,
403
+ onwarn: () => {},
404
+ moduleSideEffects: (id) => file === id,
405
+ external: (importee) => (
406
+ importee.startsWith('aws-sdk') ||
407
+ importee.startsWith('@aws-sdk')
408
+ ),
409
+ })
410
+
411
+ const hash = createHash('sha1').update(code).digest('hex')
412
+
413
+ parentPort.postMessage(JSON.stringify({
414
+ handler: 'index.default',
415
+ hash,
416
+ files: [
417
+ { name: 'index.js', code, map: map?.toString() }
418
+ ]
419
+ }))
420
+ }
421
+
422
+ build(workerData)
423
+ `;
385
424
  var defaultBuild = async (file) => {
386
- const output = await (0, import_core3.bundle)({
387
- entry: {
388
- file
389
- },
390
- mode: "production",
391
- target: "node",
392
- externalModules: [
393
- "@aws-sdk/*",
394
- "@aws-sdk",
395
- "aws-sdk"
396
- ],
397
- module: {},
398
- options: {
399
- minify: true,
400
- sourceMaps: true,
401
- jsc: {
402
- target: "es2022"
425
+ return new Promise((resolve, reject) => {
426
+ const worker = new import_worker_threads.Worker(workerCode, { workerData: file, eval: true });
427
+ const cleanUp2 = () => {
428
+ worker.removeAllListeners();
429
+ worker.terminate();
430
+ };
431
+ worker.on("message", (data) => {
432
+ resolve(JSON.parse(data.toString("utf8")));
433
+ cleanUp2();
434
+ });
435
+ worker.on("error", (data) => {
436
+ reject(data);
437
+ cleanUp2();
438
+ });
439
+ worker.on("exit", (code) => {
440
+ if (code !== 0) {
441
+ reject(new Error(`Worker exited with code ${code}`));
442
+ cleanUp2();
403
443
  }
404
- },
405
- output: {
406
- name: "output",
407
- path: ""
408
- }
444
+ });
409
445
  });
410
- const hash = (0, import_crypto.createHash)("sha1").update(output.file.code).digest("hex");
411
- return {
412
- handler: "index.default",
413
- hash,
414
- files: [
415
- {
416
- name: "index.js",
417
- code: output.file.code,
418
- map: output.file.map?.toString()
419
- }
420
- ]
421
- };
422
446
  };
423
447
 
424
448
  // src/plugins/function/util/build.ts
@@ -445,13 +469,13 @@ var writeBuildHash = async (config2, stack, id, hash) => {
445
469
  await (0, import_promises2.writeFile)(versionFile, hash);
446
470
  };
447
471
  var writeBuildFiles = async (config2, stack, id, files) => {
448
- const bundle2 = await zipFiles(files);
472
+ const bundle = await zipFiles(files);
449
473
  const funcPath = (0, import_path3.join)(functionDir, config2.name, stack.artifactId, id);
450
474
  const filesPath = (0, import_path3.join)(funcPath, "files");
451
475
  const bundleFile = (0, import_path3.join)(funcPath, "bundle.zip");
452
- debug("Bundle size of", style.info((0, import_path3.join)(config2.name, stack.artifactId, id)), "is", style.attr((0, import_filesize.filesize)(bundle2.byteLength)));
476
+ debug("Bundle size of", style.info((0, import_path3.join)(config2.name, stack.artifactId, id)), "is", style.attr((0, import_filesize.filesize)(bundle.byteLength)));
453
477
  await (0, import_promises2.mkdir)(filesPath, { recursive: true });
454
- await (0, import_promises2.writeFile)(bundleFile, bundle2);
478
+ await (0, import_promises2.writeFile)(bundleFile, bundle);
455
479
  await Promise.all(files.map(async (file) => {
456
480
  const fileName = (0, import_path3.join)(filesPath, file.name);
457
481
  await (0, import_promises2.mkdir)((0, import_path3.basename)(fileName), { recursive: true });
@@ -463,7 +487,7 @@ var writeBuildFiles = async (config2, stack, id, files) => {
463
487
  }));
464
488
  return {
465
489
  file: bundleFile,
466
- size: bundle2.byteLength
490
+ size: bundle.byteLength
467
491
  };
468
492
  };
469
493
 
@@ -622,12 +646,12 @@ var toFunction = ({ config: config2, stack, stackConfig, assets }, id, fileOrPro
622
646
  resourceName: id,
623
647
  async build() {
624
648
  const result = await defaultBuild(props.file);
625
- const bundle2 = await writeBuildFiles(config2, stack, id, result.files);
649
+ const bundle = await writeBuildFiles(config2, stack, id, result.files);
626
650
  await writeBuildHash(config2, stack, id, result.hash);
627
651
  const func = lambda.node.defaultChild;
628
652
  func.handler = result.handler;
629
653
  return {
630
- size: formatByteSize(bundle2.size)
654
+ size: formatByteSize(bundle.size)
631
655
  };
632
656
  },
633
657
  async publish() {
@@ -1244,7 +1268,7 @@ var AppSchema = import_zod23.z.object({
1244
1268
  });
1245
1269
 
1246
1270
  // src/util/import.ts
1247
- var import_core4 = require("@swc/core");
1271
+ var import_core3 = require("@swc/core");
1248
1272
  var import_path7 = require("path");
1249
1273
  var import_promises4 = require("fs/promises");
1250
1274
  var resolveFileNameExtension = async (path) => {
@@ -1274,7 +1298,7 @@ var resolveDir = (path) => {
1274
1298
  };
1275
1299
  var importFile = async (path) => {
1276
1300
  const load = async (file) => {
1277
- let { code: code2 } = await (0, import_core4.transformFile)(file, {
1301
+ let { code: code2 } = await (0, import_core3.transformFile)(file, {
1278
1302
  isModule: true
1279
1303
  });
1280
1304
  const path2 = (0, import_path7.dirname)(file);
package/dist/bin.js CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
+ __require,
3
4
  definePlugin
4
- } from "./chunk-PFTL6L4F.js";
5
+ } from "./chunk-6KILQ5DR.js";
5
6
 
6
7
  // src/cli/program.ts
7
8
  import { Command } from "commander";
@@ -357,45 +358,69 @@ var SizeSchema = z7.custom((value) => {
357
358
  }, "Invalid size").transform(toSize);
358
359
 
359
360
  // src/plugins/function/util/build-worker.ts
360
- import { bundle } from "@swc/core";
361
+ import { Worker } from "worker_threads";
362
+ var cjs = typeof __require !== "undefined";
363
+ var importESM = `
364
+ import { bundle } from "@awsless/code";
361
365
  import { createHash } from "crypto";
366
+ import { parentPort, workerData } from "worker_threads";
367
+ `;
368
+ var importCJS = `
369
+ const { bundle } = require("@awsless/code");
370
+ const { createHash } = require("crypto");
371
+ const { parentPort, workerData } = require("worker_threads");
372
+ `;
373
+ var workerCode = `
374
+ ${cjs ? importCJS : importESM}
375
+
376
+ const build = async (file) => {
377
+ const { code, map } = await bundle(file, {
378
+ format: 'esm',
379
+ sourceMap: true,
380
+ minimize: true,
381
+ onwarn: () => {},
382
+ moduleSideEffects: (id) => file === id,
383
+ external: (importee) => (
384
+ importee.startsWith('aws-sdk') ||
385
+ importee.startsWith('@aws-sdk')
386
+ ),
387
+ })
388
+
389
+ const hash = createHash('sha1').update(code).digest('hex')
390
+
391
+ parentPort.postMessage(JSON.stringify({
392
+ handler: 'index.default',
393
+ hash,
394
+ files: [
395
+ { name: 'index.js', code, map: map?.toString() }
396
+ ]
397
+ }))
398
+ }
399
+
400
+ build(workerData)
401
+ `;
362
402
  var defaultBuild = async (file) => {
363
- const output = await bundle({
364
- entry: {
365
- file
366
- },
367
- mode: "production",
368
- target: "node",
369
- externalModules: [
370
- "@aws-sdk/*",
371
- "@aws-sdk",
372
- "aws-sdk"
373
- ],
374
- module: {},
375
- options: {
376
- minify: true,
377
- sourceMaps: true,
378
- jsc: {
379
- target: "es2022"
403
+ return new Promise((resolve, reject) => {
404
+ const worker = new Worker(workerCode, { workerData: file, eval: true });
405
+ const cleanUp2 = () => {
406
+ worker.removeAllListeners();
407
+ worker.terminate();
408
+ };
409
+ worker.on("message", (data) => {
410
+ resolve(JSON.parse(data.toString("utf8")));
411
+ cleanUp2();
412
+ });
413
+ worker.on("error", (data) => {
414
+ reject(data);
415
+ cleanUp2();
416
+ });
417
+ worker.on("exit", (code) => {
418
+ if (code !== 0) {
419
+ reject(new Error(`Worker exited with code ${code}`));
420
+ cleanUp2();
380
421
  }
381
- },
382
- output: {
383
- name: "output",
384
- path: ""
385
- }
422
+ });
386
423
  });
387
- const hash = createHash("sha1").update(output.file.code).digest("hex");
388
- return {
389
- handler: "index.default",
390
- hash,
391
- files: [
392
- {
393
- name: "index.js",
394
- code: output.file.code,
395
- map: output.file.map?.toString()
396
- }
397
- ]
398
- };
399
424
  };
400
425
 
401
426
  // src/plugins/function/util/build.ts
@@ -422,13 +447,13 @@ var writeBuildHash = async (config2, stack, id, hash) => {
422
447
  await writeFile(versionFile, hash);
423
448
  };
424
449
  var writeBuildFiles = async (config2, stack, id, files) => {
425
- const bundle2 = await zipFiles(files);
450
+ const bundle = await zipFiles(files);
426
451
  const funcPath = join2(functionDir, config2.name, stack.artifactId, id);
427
452
  const filesPath = join2(funcPath, "files");
428
453
  const bundleFile = join2(funcPath, "bundle.zip");
429
- debug("Bundle size of", style.info(join2(config2.name, stack.artifactId, id)), "is", style.attr(filesize(bundle2.byteLength)));
454
+ debug("Bundle size of", style.info(join2(config2.name, stack.artifactId, id)), "is", style.attr(filesize(bundle.byteLength)));
430
455
  await mkdir(filesPath, { recursive: true });
431
- await writeFile(bundleFile, bundle2);
456
+ await writeFile(bundleFile, bundle);
432
457
  await Promise.all(files.map(async (file) => {
433
458
  const fileName = join2(filesPath, file.name);
434
459
  await mkdir(basename(fileName), { recursive: true });
@@ -440,7 +465,7 @@ var writeBuildFiles = async (config2, stack, id, files) => {
440
465
  }));
441
466
  return {
442
467
  file: bundleFile,
443
- size: bundle2.byteLength
468
+ size: bundle.byteLength
444
469
  };
445
470
  };
446
471
 
@@ -599,12 +624,12 @@ var toFunction = ({ config: config2, stack, stackConfig, assets }, id, fileOrPro
599
624
  resourceName: id,
600
625
  async build() {
601
626
  const result = await defaultBuild(props.file);
602
- const bundle2 = await writeBuildFiles(config2, stack, id, result.files);
627
+ const bundle = await writeBuildFiles(config2, stack, id, result.files);
603
628
  await writeBuildHash(config2, stack, id, result.hash);
604
629
  const func = lambda.node.defaultChild;
605
630
  func.handler = result.handler;
606
631
  return {
607
- size: formatByteSize(bundle2.size)
632
+ size: formatByteSize(bundle.size)
608
633
  };
609
634
  },
610
635
  async publish() {
@@ -0,0 +1,15 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined")
5
+ return require.apply(this, arguments);
6
+ throw new Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+
9
+ // src/plugin.ts
10
+ var definePlugin = (plugin) => plugin;
11
+
12
+ export {
13
+ __require,
14
+ definePlugin
15
+ };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  definePlugin
3
- } from "./chunk-PFTL6L4F.js";
3
+ } from "./chunk-6KILQ5DR.js";
4
4
  export {
5
5
  definePlugin
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/awsless",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {
@@ -37,6 +37,7 @@
37
37
  "chalk": "^5.3.0",
38
38
  "change-case": "^4.1.2",
39
39
  "commander": "^9.4.1",
40
+ "esbuild": "^0.18.15",
40
41
  "filesize": "^10.0.7",
41
42
  "jszip": "^3.10.1",
42
43
  "pretty-hrtime": "^1.0.3",
@@ -1,6 +0,0 @@
1
- // src/plugin.ts
2
- var definePlugin = (plugin) => plugin;
3
-
4
- export {
5
- definePlugin
6
- };