@awsless/awsless 0.0.6 → 0.0.7

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,69 +380,45 @@ 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_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
- `;
383
+ var import_core3 = require("@swc/core");
384
+ var import_crypto = require("crypto");
424
385
  var defaultBuild = async (file) => {
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();
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"
443
403
  }
444
- });
404
+ },
405
+ output: {
406
+ name: "output",
407
+ path: ""
408
+ }
445
409
  });
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
+ };
446
422
  };
447
423
 
448
424
  // src/plugins/function/util/build.ts
@@ -469,13 +445,13 @@ var writeBuildHash = async (config2, stack, id, hash) => {
469
445
  await (0, import_promises2.writeFile)(versionFile, hash);
470
446
  };
471
447
  var writeBuildFiles = async (config2, stack, id, files) => {
472
- const bundle = await zipFiles(files);
448
+ const bundle2 = await zipFiles(files);
473
449
  const funcPath = (0, import_path3.join)(functionDir, config2.name, stack.artifactId, id);
474
450
  const filesPath = (0, import_path3.join)(funcPath, "files");
475
451
  const bundleFile = (0, import_path3.join)(funcPath, "bundle.zip");
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)));
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)));
477
453
  await (0, import_promises2.mkdir)(filesPath, { recursive: true });
478
- await (0, import_promises2.writeFile)(bundleFile, bundle);
454
+ await (0, import_promises2.writeFile)(bundleFile, bundle2);
479
455
  await Promise.all(files.map(async (file) => {
480
456
  const fileName = (0, import_path3.join)(filesPath, file.name);
481
457
  await (0, import_promises2.mkdir)((0, import_path3.basename)(fileName), { recursive: true });
@@ -487,7 +463,7 @@ var writeBuildFiles = async (config2, stack, id, files) => {
487
463
  }));
488
464
  return {
489
465
  file: bundleFile,
490
- size: bundle.byteLength
466
+ size: bundle2.byteLength
491
467
  };
492
468
  };
493
469
 
@@ -646,12 +622,12 @@ var toFunction = ({ config: config2, stack, stackConfig, assets }, id, fileOrPro
646
622
  resourceName: id,
647
623
  async build() {
648
624
  const result = await defaultBuild(props.file);
649
- const bundle = await writeBuildFiles(config2, stack, id, result.files);
625
+ const bundle2 = await writeBuildFiles(config2, stack, id, result.files);
650
626
  await writeBuildHash(config2, stack, id, result.hash);
651
627
  const func = lambda.node.defaultChild;
652
628
  func.handler = result.handler;
653
629
  return {
654
- size: formatByteSize(bundle.size)
630
+ size: formatByteSize(bundle2.size)
655
631
  };
656
632
  },
657
633
  async publish() {
@@ -1268,7 +1244,7 @@ var AppSchema = import_zod23.z.object({
1268
1244
  });
1269
1245
 
1270
1246
  // src/util/import.ts
1271
- var import_core3 = require("@swc/core");
1247
+ var import_core4 = require("@swc/core");
1272
1248
  var import_path7 = require("path");
1273
1249
  var import_promises4 = require("fs/promises");
1274
1250
  var resolveFileNameExtension = async (path) => {
@@ -1298,7 +1274,7 @@ var resolveDir = (path) => {
1298
1274
  };
1299
1275
  var importFile = async (path) => {
1300
1276
  const load = async (file) => {
1301
- let { code: code2 } = await (0, import_core3.transformFile)(file, {
1277
+ let { code: code2 } = await (0, import_core4.transformFile)(file, {
1302
1278
  isModule: true
1303
1279
  });
1304
1280
  const path2 = (0, import_path7.dirname)(file);
package/dist/bin.js CHANGED
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- __require,
4
3
  definePlugin
5
- } from "./chunk-6KILQ5DR.js";
4
+ } from "./chunk-PFTL6L4F.js";
6
5
 
7
6
  // src/cli/program.ts
8
7
  import { Command } from "commander";
@@ -358,69 +357,45 @@ var SizeSchema = z7.custom((value) => {
358
357
  }, "Invalid size").transform(toSize);
359
358
 
360
359
  // src/plugins/function/util/build-worker.ts
361
- import { Worker } from "worker_threads";
362
- var cjs = typeof __require !== "undefined";
363
- var importESM = `
364
- import { bundle } from "@awsless/code";
360
+ import { bundle } from "@swc/core";
365
361
  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
- `;
402
362
  var defaultBuild = async (file) => {
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();
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"
421
380
  }
422
- });
381
+ },
382
+ output: {
383
+ name: "output",
384
+ path: ""
385
+ }
423
386
  });
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
+ };
424
399
  };
425
400
 
426
401
  // src/plugins/function/util/build.ts
@@ -447,13 +422,13 @@ var writeBuildHash = async (config2, stack, id, hash) => {
447
422
  await writeFile(versionFile, hash);
448
423
  };
449
424
  var writeBuildFiles = async (config2, stack, id, files) => {
450
- const bundle = await zipFiles(files);
425
+ const bundle2 = await zipFiles(files);
451
426
  const funcPath = join2(functionDir, config2.name, stack.artifactId, id);
452
427
  const filesPath = join2(funcPath, "files");
453
428
  const bundleFile = join2(funcPath, "bundle.zip");
454
- debug("Bundle size of", style.info(join2(config2.name, stack.artifactId, id)), "is", style.attr(filesize(bundle.byteLength)));
429
+ debug("Bundle size of", style.info(join2(config2.name, stack.artifactId, id)), "is", style.attr(filesize(bundle2.byteLength)));
455
430
  await mkdir(filesPath, { recursive: true });
456
- await writeFile(bundleFile, bundle);
431
+ await writeFile(bundleFile, bundle2);
457
432
  await Promise.all(files.map(async (file) => {
458
433
  const fileName = join2(filesPath, file.name);
459
434
  await mkdir(basename(fileName), { recursive: true });
@@ -465,7 +440,7 @@ var writeBuildFiles = async (config2, stack, id, files) => {
465
440
  }));
466
441
  return {
467
442
  file: bundleFile,
468
- size: bundle.byteLength
443
+ size: bundle2.byteLength
469
444
  };
470
445
  };
471
446
 
@@ -624,12 +599,12 @@ var toFunction = ({ config: config2, stack, stackConfig, assets }, id, fileOrPro
624
599
  resourceName: id,
625
600
  async build() {
626
601
  const result = await defaultBuild(props.file);
627
- const bundle = await writeBuildFiles(config2, stack, id, result.files);
602
+ const bundle2 = await writeBuildFiles(config2, stack, id, result.files);
628
603
  await writeBuildHash(config2, stack, id, result.hash);
629
604
  const func = lambda.node.defaultChild;
630
605
  func.handler = result.handler;
631
606
  return {
632
- size: formatByteSize(bundle.size)
607
+ size: formatByteSize(bundle2.size)
633
608
  };
634
609
  },
635
610
  async publish() {
@@ -0,0 +1,6 @@
1
+ // src/plugin.ts
2
+ var definePlugin = (plugin) => plugin;
3
+
4
+ export {
5
+ definePlugin
6
+ };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  definePlugin
3
- } from "./chunk-6KILQ5DR.js";
3
+ } from "./chunk-PFTL6L4F.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.6",
3
+ "version": "0.0.7",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {
@@ -1,15 +0,0 @@
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
- };