@awsless/awsless 0.0.248 → 0.0.250
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.js +205 -158
- package/package.json +6 -5
package/dist/bin.js
CHANGED
|
@@ -1801,13 +1801,13 @@ var TypeObject = class {
|
|
|
1801
1801
|
|
|
1802
1802
|
// src/util/name.ts
|
|
1803
1803
|
import { paramCase as paramCase3 } from "change-case";
|
|
1804
|
-
var formatGlobalResourceName = (appName, ns, id) => {
|
|
1804
|
+
var formatGlobalResourceName = (appName, ns, id, seperator = "--") => {
|
|
1805
1805
|
return [
|
|
1806
1806
|
//
|
|
1807
1807
|
appName,
|
|
1808
1808
|
ns,
|
|
1809
1809
|
id
|
|
1810
|
-
].map((v) => paramCase3(v)).join(
|
|
1810
|
+
].map((v) => paramCase3(v)).join(seperator);
|
|
1811
1811
|
};
|
|
1812
1812
|
var formatLocalResourceName = (appName, stackName, ns, id, seperator = "--") => {
|
|
1813
1813
|
return [
|
|
@@ -1890,6 +1890,104 @@ import { Node as Node3, aws as aws3 } from "@awsless/formation";
|
|
|
1890
1890
|
// src/feature/function/util.ts
|
|
1891
1891
|
import { Asset, aws as aws2 } from "@awsless/formation";
|
|
1892
1892
|
import deepmerge from "deepmerge";
|
|
1893
|
+
import { basename as basename4, dirname as dirname6, extname as extname3 } from "path";
|
|
1894
|
+
import { exec } from "promisify-child-process";
|
|
1895
|
+
|
|
1896
|
+
// src/build/index.ts
|
|
1897
|
+
import { mkdir, readFile as readFile2, writeFile } from "fs/promises";
|
|
1898
|
+
import { dirname as dirname3, join as join5 } from "path";
|
|
1899
|
+
|
|
1900
|
+
// old/util/timer.ts
|
|
1901
|
+
import hrtime from "pretty-hrtime";
|
|
1902
|
+
|
|
1903
|
+
// old/cli/style.ts
|
|
1904
|
+
import chalk2 from "chalk";
|
|
1905
|
+
var style = {
|
|
1906
|
+
primary: chalk2.bold.hex("#FF9000"),
|
|
1907
|
+
// title: chalk.white,
|
|
1908
|
+
normal: chalk2.white,
|
|
1909
|
+
label: chalk2.white.bold,
|
|
1910
|
+
placeholder: chalk2.dim,
|
|
1911
|
+
link: chalk2.cyan,
|
|
1912
|
+
info: chalk2.blue,
|
|
1913
|
+
success: chalk2.green,
|
|
1914
|
+
warning: chalk2.yellow,
|
|
1915
|
+
error: chalk2.red,
|
|
1916
|
+
attr: chalk2.yellow,
|
|
1917
|
+
cursor: chalk2.bgWhite.blackBright
|
|
1918
|
+
};
|
|
1919
|
+
|
|
1920
|
+
// old/util/timer.ts
|
|
1921
|
+
var createTimer = () => {
|
|
1922
|
+
const start = process.hrtime();
|
|
1923
|
+
return () => {
|
|
1924
|
+
const end = process.hrtime(start);
|
|
1925
|
+
const [time, unit] = hrtime(end).split(" ");
|
|
1926
|
+
return style.attr(time) + style.attr.dim(unit);
|
|
1927
|
+
};
|
|
1928
|
+
};
|
|
1929
|
+
|
|
1930
|
+
// src/build/index.ts
|
|
1931
|
+
var readCache = async (file) => {
|
|
1932
|
+
try {
|
|
1933
|
+
const value = await readFile2(file, "utf8");
|
|
1934
|
+
return JSON.parse(value);
|
|
1935
|
+
} catch (_) {
|
|
1936
|
+
return void 0;
|
|
1937
|
+
}
|
|
1938
|
+
};
|
|
1939
|
+
var writeCache = async (file, version, data) => {
|
|
1940
|
+
const cache = JSON.stringify({ version, data });
|
|
1941
|
+
const base = dirname3(file);
|
|
1942
|
+
await mkdir(base, { recursive: true });
|
|
1943
|
+
await writeFile(file, cache, "utf8");
|
|
1944
|
+
};
|
|
1945
|
+
var getBuildPath = (type, name, file) => {
|
|
1946
|
+
return join5(directories.build, type, name, file);
|
|
1947
|
+
};
|
|
1948
|
+
var build = (type, name, builder) => {
|
|
1949
|
+
return builder(async (version, callback) => {
|
|
1950
|
+
const cacheFile = getBuildPath(type, name, "cache.json");
|
|
1951
|
+
const cache = await readCache(cacheFile);
|
|
1952
|
+
if (cache && cache.version === version && !process.env.NO_CACHE) {
|
|
1953
|
+
return {
|
|
1954
|
+
...cache.data,
|
|
1955
|
+
cached: true
|
|
1956
|
+
};
|
|
1957
|
+
}
|
|
1958
|
+
const time = createTimer();
|
|
1959
|
+
const meta = await callback(async (file, data2) => {
|
|
1960
|
+
const path = getBuildPath(type, name, file);
|
|
1961
|
+
const base = dirname3(path);
|
|
1962
|
+
await mkdir(base, { recursive: true });
|
|
1963
|
+
await writeFile(path, data2);
|
|
1964
|
+
});
|
|
1965
|
+
const data = { ...meta, buildTime: time() };
|
|
1966
|
+
await writeCache(cacheFile, version, data);
|
|
1967
|
+
return {
|
|
1968
|
+
...data,
|
|
1969
|
+
cached: false
|
|
1970
|
+
};
|
|
1971
|
+
});
|
|
1972
|
+
};
|
|
1973
|
+
|
|
1974
|
+
// src/util/byte-size.ts
|
|
1975
|
+
import { filesize } from "filesize";
|
|
1976
|
+
var formatByteSize = (size) => {
|
|
1977
|
+
const [number, unit] = filesize(size).toString().split(" ");
|
|
1978
|
+
return color.attr(number) + color.attr.dim(unit);
|
|
1979
|
+
};
|
|
1980
|
+
|
|
1981
|
+
// src/feature/on-failure/util.ts
|
|
1982
|
+
var getGlobalOnFailure = (ctx) => {
|
|
1983
|
+
return hasOnFailure(ctx.stackConfigs) ? ctx.shared.get("on-failure-queue-arn") : void 0;
|
|
1984
|
+
};
|
|
1985
|
+
var hasOnFailure = (stacks) => {
|
|
1986
|
+
const onFailure = stacks.find((stack) => {
|
|
1987
|
+
return typeof stack.onFailure !== "undefined";
|
|
1988
|
+
});
|
|
1989
|
+
return !!onFailure;
|
|
1990
|
+
};
|
|
1893
1991
|
|
|
1894
1992
|
// src/feature/function/build/typescript/bundle.ts
|
|
1895
1993
|
import { rollup } from "rollup";
|
|
@@ -1898,7 +1996,7 @@ import { swc, minify as swcMinify } from "rollup-plugin-swc3";
|
|
|
1898
1996
|
import json from "@rollup/plugin-json";
|
|
1899
1997
|
import commonjs from "@rollup/plugin-commonjs";
|
|
1900
1998
|
import nodeResolve from "@rollup/plugin-node-resolve";
|
|
1901
|
-
import { dirname as
|
|
1999
|
+
import { dirname as dirname4 } from "path";
|
|
1902
2000
|
var bundleTypeScript = async ({ format: format2 = "esm", minify = true, file }) => {
|
|
1903
2001
|
const bundle = await rollup({
|
|
1904
2002
|
input: file,
|
|
@@ -1921,7 +2019,7 @@ var bundleTypeScript = async ({ format: format2 = "esm", minify = true, file })
|
|
|
1921
2019
|
// minify,
|
|
1922
2020
|
// module: true,
|
|
1923
2021
|
jsc: {
|
|
1924
|
-
baseUrl:
|
|
2022
|
+
baseUrl: dirname4(file),
|
|
1925
2023
|
minify: { sourceMap: true }
|
|
1926
2024
|
},
|
|
1927
2025
|
sourceMaps: true
|
|
@@ -1965,26 +2063,10 @@ var bundleTypeScript = async ({ format: format2 = "esm", minify = true, file })
|
|
|
1965
2063
|
};
|
|
1966
2064
|
};
|
|
1967
2065
|
|
|
1968
|
-
// src/feature/function/build/zip.ts
|
|
1969
|
-
import JSZip from "jszip";
|
|
1970
|
-
var zipFiles = (files) => {
|
|
1971
|
-
const zip = new JSZip();
|
|
1972
|
-
for (const file of files) {
|
|
1973
|
-
zip.file(file.name, file.code);
|
|
1974
|
-
}
|
|
1975
|
-
return zip.generateAsync({
|
|
1976
|
-
type: "nodebuffer",
|
|
1977
|
-
compression: "DEFLATE",
|
|
1978
|
-
compressionOptions: {
|
|
1979
|
-
level: 9
|
|
1980
|
-
}
|
|
1981
|
-
});
|
|
1982
|
-
};
|
|
1983
|
-
|
|
1984
2066
|
// src/feature/function/build/typescript/fingerprint.ts
|
|
1985
2067
|
import { createHash as createHash2 } from "crypto";
|
|
1986
|
-
import { readFile as
|
|
1987
|
-
import { basename as basename3, dirname as
|
|
2068
|
+
import { readFile as readFile3, readdir, stat as stat3 } from "fs/promises";
|
|
2069
|
+
import { basename as basename3, dirname as dirname5, extname as extname2, join as join6 } from "path";
|
|
1988
2070
|
import parseStaticImports from "parse-static-imports";
|
|
1989
2071
|
var extensions = ["js", "mjs", "jsx", "ts", "mts", "tsx"];
|
|
1990
2072
|
var generateFileHashes = async (file, hashes) => {
|
|
@@ -2015,17 +2097,17 @@ var readModuleFile = (file) => {
|
|
|
2015
2097
|
return readFiles([
|
|
2016
2098
|
file,
|
|
2017
2099
|
...extensions.map((exp) => `${file}.${exp}`),
|
|
2018
|
-
...extensions.map((exp) =>
|
|
2100
|
+
...extensions.map((exp) => join6(file, `/index.${exp}`))
|
|
2019
2101
|
]);
|
|
2020
2102
|
}
|
|
2021
|
-
return
|
|
2103
|
+
return readFile3(file, "utf8");
|
|
2022
2104
|
};
|
|
2023
2105
|
var readFiles = async (files) => {
|
|
2024
2106
|
for (const file of files) {
|
|
2025
2107
|
try {
|
|
2026
2108
|
const s = await stat3(file);
|
|
2027
2109
|
if (s.isFile()) {
|
|
2028
|
-
return
|
|
2110
|
+
return readFile3(file, "utf8");
|
|
2029
2111
|
}
|
|
2030
2112
|
} catch (_) {
|
|
2031
2113
|
continue;
|
|
@@ -2035,105 +2117,25 @@ var readFiles = async (files) => {
|
|
|
2035
2117
|
};
|
|
2036
2118
|
var findDependencies = async (file, code) => {
|
|
2037
2119
|
const imports = await parseStaticImports(code);
|
|
2038
|
-
return imports.map((entry) => entry.moduleName).filter(Boolean).map((value) => value?.startsWith(".") ?
|
|
2039
|
-
};
|
|
2040
|
-
|
|
2041
|
-
// src/util/byte-size.ts
|
|
2042
|
-
import { filesize } from "filesize";
|
|
2043
|
-
var formatByteSize = (size) => {
|
|
2044
|
-
const [number, unit] = filesize(size).toString().split(" ");
|
|
2045
|
-
return color.attr(number) + color.attr.dim(unit);
|
|
2120
|
+
return imports.map((entry) => entry.moduleName).filter(Boolean).map((value) => value?.startsWith(".") ? join6(dirname5(file), value) : value);
|
|
2046
2121
|
};
|
|
2047
2122
|
|
|
2048
|
-
// src/build/
|
|
2049
|
-
import
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
// old/cli/style.ts
|
|
2056
|
-
import chalk2 from "chalk";
|
|
2057
|
-
var style = {
|
|
2058
|
-
primary: chalk2.bold.hex("#FF9000"),
|
|
2059
|
-
// title: chalk.white,
|
|
2060
|
-
normal: chalk2.white,
|
|
2061
|
-
label: chalk2.white.bold,
|
|
2062
|
-
placeholder: chalk2.dim,
|
|
2063
|
-
link: chalk2.cyan,
|
|
2064
|
-
info: chalk2.blue,
|
|
2065
|
-
success: chalk2.green,
|
|
2066
|
-
warning: chalk2.yellow,
|
|
2067
|
-
error: chalk2.red,
|
|
2068
|
-
attr: chalk2.yellow,
|
|
2069
|
-
cursor: chalk2.bgWhite.blackBright
|
|
2070
|
-
};
|
|
2071
|
-
|
|
2072
|
-
// old/util/timer.ts
|
|
2073
|
-
var createTimer = () => {
|
|
2074
|
-
const start = process.hrtime();
|
|
2075
|
-
return () => {
|
|
2076
|
-
const end = process.hrtime(start);
|
|
2077
|
-
const [time, unit] = hrtime(end).split(" ");
|
|
2078
|
-
return style.attr(time) + style.attr.dim(unit);
|
|
2079
|
-
};
|
|
2080
|
-
};
|
|
2081
|
-
|
|
2082
|
-
// src/build/index.ts
|
|
2083
|
-
var readCache = async (file) => {
|
|
2084
|
-
try {
|
|
2085
|
-
const value = await readFile3(file, "utf8");
|
|
2086
|
-
return JSON.parse(value);
|
|
2087
|
-
} catch (_) {
|
|
2088
|
-
return void 0;
|
|
2123
|
+
// src/feature/function/build/zip.ts
|
|
2124
|
+
import JSZip from "jszip";
|
|
2125
|
+
var zipFiles = (files) => {
|
|
2126
|
+
const zip = new JSZip();
|
|
2127
|
+
for (const file of files) {
|
|
2128
|
+
zip.file(file.name, file.code);
|
|
2089
2129
|
}
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
await writeFile(file, cache, "utf8");
|
|
2096
|
-
};
|
|
2097
|
-
var getBuildPath = (type, name, file) => {
|
|
2098
|
-
return join6(directories.build, type, name, file);
|
|
2099
|
-
};
|
|
2100
|
-
var build = (type, name, builder) => {
|
|
2101
|
-
return builder(async (version, callback) => {
|
|
2102
|
-
const cacheFile = getBuildPath(type, name, "cache.json");
|
|
2103
|
-
const cache = await readCache(cacheFile);
|
|
2104
|
-
if (cache && cache.version === version && !process.env.NO_CACHE) {
|
|
2105
|
-
return {
|
|
2106
|
-
...cache.data,
|
|
2107
|
-
cached: true
|
|
2108
|
-
};
|
|
2130
|
+
return zip.generateAsync({
|
|
2131
|
+
type: "nodebuffer",
|
|
2132
|
+
compression: "DEFLATE",
|
|
2133
|
+
compressionOptions: {
|
|
2134
|
+
level: 9
|
|
2109
2135
|
}
|
|
2110
|
-
const time = createTimer();
|
|
2111
|
-
const meta = await callback(async (file, data2) => {
|
|
2112
|
-
const path = getBuildPath(type, name, file);
|
|
2113
|
-
const base = dirname5(path);
|
|
2114
|
-
await mkdir(base, { recursive: true });
|
|
2115
|
-
await writeFile(path, data2);
|
|
2116
|
-
});
|
|
2117
|
-
const data = { ...meta, buildTime: time() };
|
|
2118
|
-
await writeCache(cacheFile, version, data);
|
|
2119
|
-
return {
|
|
2120
|
-
...data,
|
|
2121
|
-
cached: false
|
|
2122
|
-
};
|
|
2123
2136
|
});
|
|
2124
2137
|
};
|
|
2125
2138
|
|
|
2126
|
-
// src/feature/on-failure/util.ts
|
|
2127
|
-
var getGlobalOnFailure = (ctx) => {
|
|
2128
|
-
return hasOnFailure(ctx.stackConfigs) ? ctx.shared.get("on-failure-queue-arn") : void 0;
|
|
2129
|
-
};
|
|
2130
|
-
var hasOnFailure = (stacks) => {
|
|
2131
|
-
const onFailure = stacks.find((stack) => {
|
|
2132
|
-
return typeof stack.onFailure !== "undefined";
|
|
2133
|
-
});
|
|
2134
|
-
return !!onFailure;
|
|
2135
|
-
};
|
|
2136
|
-
|
|
2137
2139
|
// src/feature/function/util.ts
|
|
2138
2140
|
var createLambdaFunction = (group, ctx, ns, id, local2) => {
|
|
2139
2141
|
let name;
|
|
@@ -2143,26 +2145,56 @@ var createLambdaFunction = (group, ctx, ns, id, local2) => {
|
|
|
2143
2145
|
name = formatGlobalResourceName(ctx.appConfig.name, ns, id);
|
|
2144
2146
|
}
|
|
2145
2147
|
const props = deepmerge(ctx.appConfig.defaults.function, local2);
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
const
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2148
|
+
const ext = extname3(props.file);
|
|
2149
|
+
let code;
|
|
2150
|
+
if ([".ts", ".js", ".tsx", ".sx"].includes(ext)) {
|
|
2151
|
+
ctx.registerBuild("function", name, async (build3) => {
|
|
2152
|
+
const version = await fingerprintFromFile(props.file);
|
|
2153
|
+
return build3(version, async (write) => {
|
|
2154
|
+
const bundle = await bundleTypeScript({ file: props.file });
|
|
2155
|
+
const archive = await zipFiles(bundle.files);
|
|
2156
|
+
await Promise.all([
|
|
2157
|
+
write("bundle.zip", archive),
|
|
2158
|
+
...bundle.files.map((file) => write(`files/${file.name}`, file.code)),
|
|
2159
|
+
...bundle.files.map((file) => file.map && write(`files/${file.name}.map`, file.map))
|
|
2160
|
+
]);
|
|
2161
|
+
return {
|
|
2162
|
+
size: formatByteSize(archive.byteLength)
|
|
2163
|
+
};
|
|
2164
|
+
});
|
|
2159
2165
|
});
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
})
|
|
2166
|
+
code = new aws2.s3.BucketObject(group, "code", {
|
|
2167
|
+
bucket: ctx.shared.get("function-bucket-name"),
|
|
2168
|
+
key: `/lambda/${name}.zip`,
|
|
2169
|
+
body: Asset.fromFile(getBuildPath("function", name, "bundle.zip"))
|
|
2170
|
+
});
|
|
2171
|
+
} else if (basename4(props.file) === "dockerfile") {
|
|
2172
|
+
ctx.registerBuild("function", name, async (build3) => {
|
|
2173
|
+
const version = Math.random().toString();
|
|
2174
|
+
return build3(version, async () => {
|
|
2175
|
+
const repoName = formatGlobalResourceName(ctx.appConfig.name, "function", "repository", "-");
|
|
2176
|
+
await exec(`docker build -t ${name} .`, {
|
|
2177
|
+
cwd: dirname6(props.file)
|
|
2178
|
+
});
|
|
2179
|
+
await exec(
|
|
2180
|
+
`docker tag ${name}:latest ${ctx.accountId}.dkr.ecr.${ctx.appConfig.region}.amazonaws.com/${repoName}:${name}`,
|
|
2181
|
+
{
|
|
2182
|
+
cwd: dirname6(props.file)
|
|
2183
|
+
}
|
|
2184
|
+
);
|
|
2185
|
+
});
|
|
2186
|
+
});
|
|
2187
|
+
const image = new aws2.ecr.Image(group, "image", {
|
|
2188
|
+
repository: ctx.shared.get("function-repository-name"),
|
|
2189
|
+
name,
|
|
2190
|
+
tag: name
|
|
2191
|
+
});
|
|
2192
|
+
code = {
|
|
2193
|
+
imageUri: image.uri
|
|
2194
|
+
};
|
|
2195
|
+
} else {
|
|
2196
|
+
throw new Error("Unknown Lambda Function type.");
|
|
2197
|
+
}
|
|
2166
2198
|
const role = new aws2.iam.Role(group, "role", {
|
|
2167
2199
|
name,
|
|
2168
2200
|
assumedBy: "lambda.amazonaws.com"
|
|
@@ -2183,8 +2215,8 @@ var createLambdaFunction = (group, ctx, ns, id, local2) => {
|
|
|
2183
2215
|
const lambda = new aws2.lambda.Function(group, `function`, {
|
|
2184
2216
|
...props,
|
|
2185
2217
|
name,
|
|
2186
|
-
code,
|
|
2187
2218
|
role: role.arn,
|
|
2219
|
+
code,
|
|
2188
2220
|
// Remove conflicting props.
|
|
2189
2221
|
vpc: void 0,
|
|
2190
2222
|
log: props.log
|
|
@@ -2570,9 +2602,9 @@ var configFeature = defineFeature({
|
|
|
2570
2602
|
});
|
|
2571
2603
|
|
|
2572
2604
|
// src/feature/function/index.ts
|
|
2605
|
+
import { aws as aws5, Node as Node5 } from "@awsless/formation";
|
|
2573
2606
|
import { camelCase as camelCase3 } from "change-case";
|
|
2574
2607
|
import { relative } from "path";
|
|
2575
|
-
import { Node as Node5, aws as aws5 } from "@awsless/formation";
|
|
2576
2608
|
var typeGenCode2 = `
|
|
2577
2609
|
import { InvokeOptions, InvokeResponse } from '@awsless/lambda'
|
|
2578
2610
|
import type { PartialDeep } from 'type-fest'
|
|
@@ -2630,6 +2662,11 @@ var functionFeature = defineFeature({
|
|
|
2630
2662
|
forceDelete: true
|
|
2631
2663
|
});
|
|
2632
2664
|
ctx.shared.set("function-bucket-name", bucket.name);
|
|
2665
|
+
const repository = new aws5.ecr.Repository(group, "repository", {
|
|
2666
|
+
name: formatGlobalResourceName(ctx.appConfig.name, "function", "repository", "-")
|
|
2667
|
+
});
|
|
2668
|
+
ctx.shared.set("function-repository-name", repository.name);
|
|
2669
|
+
ctx.shared.set("function-repository-uri", repository.uri);
|
|
2633
2670
|
},
|
|
2634
2671
|
onStack(ctx) {
|
|
2635
2672
|
for (const [id, props] of Object.entries(ctx.stackConfig.functions || {})) {
|
|
@@ -2668,7 +2705,7 @@ var formatFullDomainName = (config2, id, subDomain) => {
|
|
|
2668
2705
|
// src/build/fingerprint.ts
|
|
2669
2706
|
import { createHash as createHash3 } from "crypto";
|
|
2670
2707
|
import { readFile as readFile4, readdir as readdir2, stat as stat4 } from "fs/promises";
|
|
2671
|
-
import { basename as
|
|
2708
|
+
import { basename as basename5, dirname as dirname7, extname as extname4, join as join7 } from "path";
|
|
2672
2709
|
import parseStaticImports2 from "parse-static-imports";
|
|
2673
2710
|
var extensions2 = ["js", "mjs", "jsx", "ts", "mts", "tsx"];
|
|
2674
2711
|
var generateFileHashes2 = async (file, hashes) => {
|
|
@@ -2695,7 +2732,7 @@ var fingerprintFromDirectory = async (dir) => {
|
|
|
2695
2732
|
const hashes = /* @__PURE__ */ new Map();
|
|
2696
2733
|
const files = await readdir2(dir, { recursive: true });
|
|
2697
2734
|
for (const file of files) {
|
|
2698
|
-
if (extensions2.includes(
|
|
2735
|
+
if (extensions2.includes(extname4(file).substring(1)) && file.at(0) !== "_") {
|
|
2699
2736
|
await generateFileHashes2(join7(dir, file), hashes);
|
|
2700
2737
|
}
|
|
2701
2738
|
}
|
|
@@ -2706,7 +2743,7 @@ var readModuleFile2 = (file) => {
|
|
|
2706
2743
|
if (file.endsWith(".js")) {
|
|
2707
2744
|
return readFiles2([file, file.substring(0, file.length - 3) + ".ts"]);
|
|
2708
2745
|
}
|
|
2709
|
-
if (!
|
|
2746
|
+
if (!basename5(file).includes(".")) {
|
|
2710
2747
|
return readFiles2([
|
|
2711
2748
|
file,
|
|
2712
2749
|
...extensions2.map((exp) => `${file}.${exp}`),
|
|
@@ -2730,7 +2767,7 @@ var readFiles2 = async (files) => {
|
|
|
2730
2767
|
};
|
|
2731
2768
|
var findDependencies2 = async (file, code) => {
|
|
2732
2769
|
const imports = await parseStaticImports2(code);
|
|
2733
|
-
return imports.map((entry) => entry.moduleName).filter(Boolean).map((value) => value?.startsWith(".") ? join7(
|
|
2770
|
+
return imports.map((entry) => entry.moduleName).filter(Boolean).map((value) => value?.startsWith(".") ? join7(dirname7(file), value) : value);
|
|
2734
2771
|
};
|
|
2735
2772
|
|
|
2736
2773
|
// src/feature/graphql/build/typescript/resolver.ts
|
|
@@ -2739,7 +2776,7 @@ import { swc as swc2, minify as swcMinify2 } from "rollup-plugin-swc3";
|
|
|
2739
2776
|
import json2 from "@rollup/plugin-json";
|
|
2740
2777
|
import commonjs2 from "@rollup/plugin-commonjs";
|
|
2741
2778
|
import nodeResolve2 from "@rollup/plugin-node-resolve";
|
|
2742
|
-
import { dirname as
|
|
2779
|
+
import { dirname as dirname8 } from "path";
|
|
2743
2780
|
var buildTypeScriptResolver = async (input, { minify = true } = {}) => {
|
|
2744
2781
|
const bundle = await rollup2({
|
|
2745
2782
|
input,
|
|
@@ -2761,7 +2798,7 @@ var buildTypeScriptResolver = async (input, { minify = true } = {}) => {
|
|
|
2761
2798
|
// minify,
|
|
2762
2799
|
// module: true,
|
|
2763
2800
|
jsc: {
|
|
2764
|
-
baseUrl:
|
|
2801
|
+
baseUrl: dirname8(input),
|
|
2765
2802
|
minify: { sourceMap: true }
|
|
2766
2803
|
},
|
|
2767
2804
|
sourceMaps: true
|
|
@@ -3211,7 +3248,7 @@ var queueFeature = defineFeature({
|
|
|
3211
3248
|
});
|
|
3212
3249
|
|
|
3213
3250
|
// src/feature/store/index.ts
|
|
3214
|
-
import {
|
|
3251
|
+
import { aws as aws10, Node as Node10 } from "@awsless/formation";
|
|
3215
3252
|
var typeGenCode4 = `
|
|
3216
3253
|
import { Body, PutObjectProps, BodyStream, createPresignedPost } from '@awsless/s3'
|
|
3217
3254
|
import { Size } from '@awsless/size'
|
|
@@ -3246,6 +3283,7 @@ var storeFeature = defineFeature({
|
|
|
3246
3283
|
onStack(ctx) {
|
|
3247
3284
|
for (const [id, props] of Object.entries(ctx.stackConfig.stores ?? {})) {
|
|
3248
3285
|
const group = new Node10(ctx.stack, "store", id);
|
|
3286
|
+
const bucketName = formatLocalResourceName(ctx.appConfig.name, ctx.stack.name, "store", id);
|
|
3249
3287
|
const lambdaConfigs = [];
|
|
3250
3288
|
const eventMap = {
|
|
3251
3289
|
"created:*": "s3:ObjectCreated:*",
|
|
@@ -3258,17 +3296,23 @@ var storeFeature = defineFeature({
|
|
|
3258
3296
|
"removed:marker": "s3:ObjectRemoved:DeleteMarkerCreated"
|
|
3259
3297
|
};
|
|
3260
3298
|
for (const [event, funcProps] of Object.entries(props.events ?? {})) {
|
|
3261
|
-
const
|
|
3299
|
+
const eventGroup = new Node10(group, "event", event);
|
|
3300
|
+
const { lambda } = createAsyncLambdaFunction(eventGroup, ctx, `store`, id, funcProps);
|
|
3301
|
+
new aws10.lambda.Permission(eventGroup, "permission", {
|
|
3302
|
+
action: "lambda:InvokeFunction",
|
|
3303
|
+
principal: "s3.amazonaws.com",
|
|
3304
|
+
functionArn: lambda.arn,
|
|
3305
|
+
sourceArn: `arn:aws:s3:::${bucketName}`
|
|
3306
|
+
});
|
|
3262
3307
|
lambdaConfigs.push({
|
|
3263
3308
|
event: eventMap[event],
|
|
3264
3309
|
function: lambda.arn
|
|
3265
3310
|
});
|
|
3266
3311
|
}
|
|
3267
3312
|
const bucket = new aws10.s3.Bucket(group, "store", {
|
|
3268
|
-
name:
|
|
3313
|
+
name: bucketName,
|
|
3269
3314
|
versioning: props.versioning,
|
|
3270
3315
|
lambdaConfigs,
|
|
3271
|
-
// cors: props.cors,
|
|
3272
3316
|
cors: [
|
|
3273
3317
|
// ---------------------------------------------
|
|
3274
3318
|
// Support for presigned post requests
|
|
@@ -3850,7 +3894,7 @@ import { join as join8 } from "path";
|
|
|
3850
3894
|
|
|
3851
3895
|
// src/feature/site/util.ts
|
|
3852
3896
|
import { lookup, contentType } from "mime-types";
|
|
3853
|
-
import { extname as
|
|
3897
|
+
import { extname as extname5 } from "path";
|
|
3854
3898
|
var getCacheControl = (file) => {
|
|
3855
3899
|
switch (lookup(file)) {
|
|
3856
3900
|
case false:
|
|
@@ -3865,7 +3909,7 @@ var getCacheControl = (file) => {
|
|
|
3865
3909
|
}
|
|
3866
3910
|
};
|
|
3867
3911
|
var getContentType = (file) => {
|
|
3868
|
-
return contentType(
|
|
3912
|
+
return contentType(extname5(file)) || "text/html; charset=utf-8";
|
|
3869
3913
|
};
|
|
3870
3914
|
|
|
3871
3915
|
// src/feature/site/index.ts
|
|
@@ -4555,10 +4599,10 @@ var config = (program2) => {
|
|
|
4555
4599
|
import { confirm as confirm3 } from "@clack/prompts";
|
|
4556
4600
|
|
|
4557
4601
|
// src/util/workspace.ts
|
|
4558
|
-
import { WorkSpace, aws as aws20, local } from "@awsless/formation";
|
|
4559
4602
|
import { minutes as minutes4 } from "@awsless/duration";
|
|
4560
|
-
import {
|
|
4603
|
+
import { aws as aws20, local, WorkSpace } from "@awsless/formation";
|
|
4561
4604
|
import { mkdir as mkdir2, readFile as readFile6, rm, writeFile as writeFile2 } from "fs/promises";
|
|
4605
|
+
import { dirname as dirname9, join as join9 } from "path";
|
|
4562
4606
|
var createWorkSpace = (props) => {
|
|
4563
4607
|
const lockProvider = new aws20.dynamodb.LockProvider({
|
|
4564
4608
|
...props,
|
|
@@ -4587,7 +4631,7 @@ var createWorkSpace = (props) => {
|
|
|
4587
4631
|
var pullRemoteState = async (app, stateProvider) => {
|
|
4588
4632
|
const file = join9(directories.state, `${app.urn}.json`);
|
|
4589
4633
|
const state2 = await stateProvider.get(app.urn);
|
|
4590
|
-
await mkdir2(
|
|
4634
|
+
await mkdir2(dirname9(file), { recursive: true });
|
|
4591
4635
|
if (typeof state2 === "undefined") {
|
|
4592
4636
|
await rm(file);
|
|
4593
4637
|
} else {
|
|
@@ -4626,6 +4670,7 @@ var del2 = (program2) => {
|
|
|
4626
4670
|
}
|
|
4627
4671
|
const { workspace, stateProvider } = createWorkSpace({
|
|
4628
4672
|
credentials,
|
|
4673
|
+
accountId,
|
|
4629
4674
|
region
|
|
4630
4675
|
});
|
|
4631
4676
|
await task("Deleting the stacks to AWS", async (update) => {
|
|
@@ -4725,10 +4770,10 @@ import { startVitest } from "vitest/node";
|
|
|
4725
4770
|
import commonjs3 from "@rollup/plugin-commonjs";
|
|
4726
4771
|
import nodeResolve3 from "@rollup/plugin-node-resolve";
|
|
4727
4772
|
import json3 from "@rollup/plugin-json";
|
|
4728
|
-
import { dirname as
|
|
4773
|
+
import { dirname as dirname10, join as join10 } from "path";
|
|
4729
4774
|
import { fileURLToPath } from "url";
|
|
4730
4775
|
var startTest = async (props) => {
|
|
4731
|
-
const __dirname =
|
|
4776
|
+
const __dirname = dirname10(fileURLToPath(import.meta.url));
|
|
4732
4777
|
const result = await startVitest(
|
|
4733
4778
|
"test",
|
|
4734
4779
|
props.filters,
|
|
@@ -4932,6 +4977,7 @@ var deploy = (program2) => {
|
|
|
4932
4977
|
await buildAssets(builders);
|
|
4933
4978
|
const { workspace, stateProvider } = createWorkSpace({
|
|
4934
4979
|
credentials,
|
|
4980
|
+
accountId,
|
|
4935
4981
|
region
|
|
4936
4982
|
});
|
|
4937
4983
|
await task("Deploying the stacks to AWS", async (update) => {
|
|
@@ -5018,7 +5064,7 @@ import { log as log9 } from "@clack/prompts";
|
|
|
5018
5064
|
|
|
5019
5065
|
// src/type-gen/generate.ts
|
|
5020
5066
|
import { mkdir as mkdir4, writeFile as writeFile4 } from "fs/promises";
|
|
5021
|
-
import { dirname as
|
|
5067
|
+
import { dirname as dirname11, join as join12, relative as relative5 } from "path";
|
|
5022
5068
|
var generateTypes = async (props) => {
|
|
5023
5069
|
const files = [];
|
|
5024
5070
|
await Promise.all(
|
|
@@ -5032,7 +5078,7 @@ var generateTypes = async (props) => {
|
|
|
5032
5078
|
if (include) {
|
|
5033
5079
|
files.push(relative5(directories.root, path));
|
|
5034
5080
|
}
|
|
5035
|
-
await mkdir4(
|
|
5081
|
+
await mkdir4(dirname11(path), { recursive: true });
|
|
5036
5082
|
await writeFile4(path, code);
|
|
5037
5083
|
}
|
|
5038
5084
|
}
|
|
@@ -5308,9 +5354,9 @@ var auth = (program2) => {
|
|
|
5308
5354
|
};
|
|
5309
5355
|
|
|
5310
5356
|
// src/cli/command/bind.ts
|
|
5311
|
-
import { spawn } from "child_process";
|
|
5312
5357
|
import { unwrap as unwrap2 } from "@awsless/formation";
|
|
5313
5358
|
import { note as note3 } from "@clack/prompts";
|
|
5359
|
+
import { spawn } from "child_process";
|
|
5314
5360
|
var bind = (program2) => {
|
|
5315
5361
|
program2.command("bind").argument("<command...>", "The command to execute").description(`Bind your site environment variables to a command`).action(async (commands7) => {
|
|
5316
5362
|
await layout("bind", async ({ appConfig, stackConfigs }) => {
|
|
@@ -5320,6 +5366,7 @@ var bind = (program2) => {
|
|
|
5320
5366
|
const { app, binds } = createApp({ appConfig, stackConfigs, accountId });
|
|
5321
5367
|
const { workspace } = createWorkSpace({
|
|
5322
5368
|
credentials,
|
|
5369
|
+
accountId,
|
|
5323
5370
|
region
|
|
5324
5371
|
});
|
|
5325
5372
|
await workspace.hydrate(app);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awsless/awsless",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.250",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"@awsless/lambda": "^0.0.19",
|
|
32
32
|
"@awsless/open-search": "^0.0.12",
|
|
33
33
|
"@awsless/redis": "^0.0.12",
|
|
34
|
-
"@awsless/s3": "^0.0.10",
|
|
35
34
|
"@awsless/sns": "^0.0.7",
|
|
35
|
+
"@awsless/s3": "^0.0.10",
|
|
36
36
|
"@awsless/sqs": "^0.0.7",
|
|
37
|
-
"@awsless/ssm": "^0.0.7",
|
|
38
37
|
"@awsless/validate": "^0.0.14",
|
|
38
|
+
"@awsless/ssm": "^0.0.7",
|
|
39
39
|
"@awsless/weak-cache": "^0.0.1"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
@@ -87,6 +87,7 @@
|
|
|
87
87
|
"parse-static-imports": "^1.1.0",
|
|
88
88
|
"pretty-hrtime": "^1.0.3",
|
|
89
89
|
"promise-dag": "^1.0.0",
|
|
90
|
+
"promisify-child-process": "^4.1.2",
|
|
90
91
|
"rollup": "^4.0.2",
|
|
91
92
|
"rollup-plugin-replace": "^2.2.0",
|
|
92
93
|
"rollup-plugin-swc3": "^0.10.2",
|
|
@@ -97,11 +98,11 @@
|
|
|
97
98
|
"wrap-ansi": "^8.1.0",
|
|
98
99
|
"zod": "^3.21.4",
|
|
99
100
|
"zod-to-json-schema": "^3.22.3",
|
|
101
|
+
"@awsless/formation": "^0.0.27",
|
|
100
102
|
"@awsless/duration": "^0.0.1",
|
|
101
|
-
"@awsless/size": "^0.0.1",
|
|
102
103
|
"@awsless/graphql": "^0.0.9",
|
|
103
104
|
"@awsless/validate": "^0.0.14",
|
|
104
|
-
"@awsless/
|
|
105
|
+
"@awsless/size": "^0.0.1",
|
|
105
106
|
"@awsless/code": "^0.0.10"
|
|
106
107
|
},
|
|
107
108
|
"scripts": {
|