@storm-software/cloudflare-tools 0.71.30 → 0.71.32

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 (36) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/{chunk-FPJU3YOH.mjs → chunk-3WBFV3XF.mjs} +7 -5
  3. package/dist/{chunk-YQGPNO3W.mjs → chunk-4WRUZBE7.mjs} +26 -20
  4. package/dist/{chunk-OZ44M6HX.js → chunk-AOAVYQNP.js} +7 -5
  5. package/dist/{chunk-YPRUPZL3.js → chunk-QDAQB4EP.js} +2 -2
  6. package/dist/{chunk-DUHFLDZ4.js → chunk-UQBLSDWU.js} +28 -22
  7. package/dist/chunk-VZQDXTIP.js +68 -0
  8. package/dist/chunk-Z2D7AKMD.mjs +68 -0
  9. package/dist/{chunk-DEX6LTPV.mjs → chunk-ZWYDXLNA.mjs} +1 -1
  10. package/dist/executors.js +2 -2
  11. package/dist/executors.mjs +2 -2
  12. package/dist/generators.js +3 -3
  13. package/dist/generators.mjs +2 -2
  14. package/dist/index.d.mts +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.js +9 -5
  17. package/dist/index.mjs +8 -4
  18. package/dist/src/executors/r2-upload-publish/executor.js +3 -3
  19. package/dist/src/executors/r2-upload-publish/executor.mjs +2 -2
  20. package/dist/src/generators/init/generator.js +2 -2
  21. package/dist/src/generators/init/generator.mjs +1 -1
  22. package/dist/src/generators/worker/generator.js +3 -3
  23. package/dist/src/generators/worker/generator.mjs +2 -2
  24. package/dist/src/utils/index.d.mts +1 -1
  25. package/dist/src/utils/index.d.ts +1 -1
  26. package/dist/src/utils/index.js +6 -2
  27. package/dist/src/utils/index.mjs +5 -1
  28. package/dist/src/utils/r2-bucket-helpers.d.mts +17 -3
  29. package/dist/src/utils/r2-bucket-helpers.d.ts +17 -3
  30. package/dist/src/utils/r2-bucket-helpers.js +6 -2
  31. package/dist/src/utils/r2-bucket-helpers.mjs +5 -1
  32. package/package.json +8 -6
  33. package/dist/chunk-RGRCKWGN.mjs +0 -225
  34. package/dist/chunk-UI2F3MMU.mjs +0 -52
  35. package/dist/chunk-ZBNASCRJ.js +0 -225
  36. package/dist/chunk-ZWHJ35F5.js +0 -52
@@ -1,225 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
-
3
-
4
- var _chunkN7FW365Qjs = require('./chunk-N7FW365Q.js');
5
-
6
-
7
-
8
- var _chunk5GILNZWSjs = require('./chunk-5GILNZWS.js');
9
-
10
-
11
- var _chunkKUGEZPUOjs = require('./chunk-KUGEZPUO.js');
12
-
13
-
14
-
15
- var _chunkZWHJ35F5js = require('./chunk-ZWHJ35F5.js');
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
- var _chunkZ2WQB55Rjs = require('./chunk-Z2WQB55R.js');
24
-
25
- // src/executors/r2-upload-publish/executor.ts
26
- var _clients3 = require('@aws-sdk/client-s3');
27
-
28
-
29
-
30
- var _devkit = require('@nx/devkit');
31
- var _glob = require('glob');
32
- var _mimetypes = require('mime-types'); var _mimetypes2 = _interopRequireDefault(_mimetypes);
33
- var _child_process = require('child_process');
34
- var _fs = require('fs');
35
- var _promises = require('fs/promises');
36
- async function runExecutor(options, context) {
37
- const isDryRun = process.env.NX_DRY_RUN === "true" || options.dryRun || false;
38
- if (!context.projectName) {
39
- throw new Error("The executor requires a projectName.");
40
- }
41
- if (!options.path) {
42
- throw new Error("The executor requires the `path` option to upload.");
43
- }
44
- console.info(
45
- `\u{1F680} Running Storm Cloudflare Publish executor on the ${context.projectName} worker`
46
- );
47
- if (!context.projectName || !_optionalChain([context, 'access', _ => _.projectsConfigurations, 'optionalAccess', _2 => _2.projects]) || !context.projectsConfigurations.projects[context.projectName] || !_optionalChain([context, 'access', _3 => _3.projectsConfigurations, 'access', _4 => _4.projects, 'access', _5 => _5[context.projectName], 'optionalAccess', _6 => _6.root])) {
48
- throw new Error("The executor requires projectsConfigurations.");
49
- }
50
- try {
51
- const workspaceRoot = _chunk5GILNZWSjs.findWorkspaceRoot.call(void 0, );
52
- const config = await _chunk5GILNZWSjs.getConfig.call(void 0, workspaceRoot);
53
- const projectName = _nullishCoalesce(_optionalChain([context, 'access', _7 => _7.projectsConfigurations, 'access', _8 => _8.projects, 'access', _9 => _9[context.projectName], 'optionalAccess', _10 => _10.name]), () => ( context.projectName));
54
- const projectDetails = _chunkN7FW365Qjs.getPackageInfo.call(void 0,
55
- context.projectsConfigurations.projects[context.projectName]
56
- );
57
- const bucketId = options.bucketId;
58
- const bucketPath = options.bucketPath || "/";
59
- if (!bucketId) {
60
- throw new Error("The executor requires a bucketId.");
61
- }
62
- const args = _chunkN7FW365Qjs.createCliOptions.call(void 0, { ...options });
63
- if (isDryRun) {
64
- args.push("--dry-run");
65
- }
66
- const cloudflareAccountId = process.env.CLOUDFLARE_ACCOUNT_ID || process.env.STORM_BOT_CLOUDFLARE_ACCOUNT;
67
- if (!_optionalChain([options, 'optionalAccess', _11 => _11.registry]) && !cloudflareAccountId) {
68
- throw new Error(
69
- "The registry option and `CLOUDFLARE_ACCOUNT_ID` (or `STORM_BOT_CLOUDFLARE_ACCOUNT`) environment variable are not set. Please set one of these values to upload to the Cloudflare R2 bucket."
70
- );
71
- }
72
- if (!process.env.STORM_BOT_ACCESS_KEY_ID && !process.env.ACCESS_KEY_ID && !process.env.CLOUDFLARE_ACCESS_KEY_ID && !process.env.AWS_ACCESS_KEY_ID || !process.env.STORM_BOT_SECRET_ACCESS_KEY && !process.env.CLOUDFLARE_SECRET_ACCESS_KEY && !process.env.SECRET_ACCESS_KEY && !process.env.AWS_SECRET_ACCESS_KEY) {
73
- throw new Error(
74
- "The `ACCESS_KEY_ID` (or `STORM_BOT_ACCESS_KEY_ID`) and `SECRET_ACCESS_KEY` (or `STORM_BOT_SECRET_ACCESS_KEY`) environment variables are not set. Please set these environment variables to upload to the Cloudflare R2 bucket."
75
- );
76
- }
77
- const registry = _optionalChain([options, 'optionalAccess', _12 => _12.registry]) ? options.registry : `https://${cloudflareAccountId}.r2.cloudflarestorage.com`;
78
- let projectGraph;
79
- try {
80
- projectGraph = _devkit.readCachedProjectGraph.call(void 0, );
81
- } catch (e) {
82
- await _devkit.createProjectGraphAsync.call(void 0, );
83
- projectGraph = _devkit.readCachedProjectGraph.call(void 0, );
84
- }
85
- if (!projectGraph) {
86
- throw new Error(
87
- "The executor failed because the project graph is not available. Please run the build command again."
88
- );
89
- }
90
- _chunkZ2WQB55Rjs.writeDebug.call(void 0,
91
- `Publishing ${context.projectName} to the ${bucketId} R2 Bucket (at ${registry})`
92
- );
93
- const client = new (0, _clients3.S3)({
94
- region: "auto",
95
- endpoint: registry,
96
- credentials: {
97
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
98
- accessKeyId: process.env.STORM_BOT_ACCESS_KEY_ID || process.env.CLOUDFLARE_ACCESS_KEY_ID || process.env.AWS_ACCESS_KEY_ID || process.env.ACCESS_KEY_ID,
99
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
100
- secretAccessKey: process.env.STORM_BOT_SECRET_ACCESS_KEY || process.env.CLOUDFLARE_SECRET_ACCESS_KEY || process.env.AWS_SECRET_ACCESS_KEY || process.env.SECRET_ACCESS_KEY
101
- },
102
- requestHandler: _chunkKUGEZPUOjs.createHttpHandler.call(void 0, )
103
- });
104
- const version = _optionalChain([projectDetails, 'optionalAccess', _13 => _13.content, 'optionalAccess', _14 => _14.version]);
105
- if (version) {
106
- _chunkZ2WQB55Rjs.writeDebug.call(void 0, `Starting upload version ${version}`);
107
- }
108
- const basePath = options.path;
109
- const files = await _glob.glob.call(void 0, _chunkZ2WQB55Rjs.joinPaths.call(void 0, basePath, "**/*"), {
110
- ignore: "**/{*.stories.tsx,*.stories.ts,*.spec.tsx,*.spec.ts}"
111
- });
112
- const internalDependencies = await _chunkZWHJ35F5js.getInternalDependencies.call(void 0,
113
- context.projectName,
114
- projectGraph
115
- );
116
- const dependencies = internalDependencies.filter(
117
- (projectNode) => !projectNode.data.tags || projectNode.data.tags.every((tag) => tag.toLowerCase() !== "component")
118
- ).reduce((ret, dep) => {
119
- if (!ret[dep.name]) {
120
- ret[dep.name] = "latest";
121
- }
122
- return ret;
123
- }, _nullishCoalesce(_optionalChain([projectDetails, 'optionalAccess', _15 => _15.content, 'access', _16 => _16.dependencies]), () => ( {})));
124
- const release = _nullishCoalesce(options.tag, () => ( _child_process.execSync.call(void 0, "npm config get tag").toString().trim()));
125
- if (options.clean === true) {
126
- _chunkZ2WQB55Rjs.writeDebug.call(void 0, `Clearing out existing items in ${bucketPath}`);
127
- if (!isDryRun) {
128
- const response = await client.listObjects({
129
- Bucket: bucketId,
130
- Prefix: !bucketPath || bucketPath === "/" ? void 0 : bucketPath
131
- });
132
- if (_optionalChain([response, 'optionalAccess', _17 => _17.Contents]) && response.Contents.length > 0) {
133
- _chunkZ2WQB55Rjs.writeTrace.call(void 0,
134
- `Deleting the following existing items from the R2 bucket path ${bucketPath}: ${response.Contents.map((item) => item.Key).join(", ")}`
135
- );
136
- await client.deleteObjects({
137
- Bucket: bucketId,
138
- Delete: {
139
- Objects: response.Contents.map((item) => ({
140
- Key: item.Key
141
- })),
142
- Quiet: false
143
- }
144
- });
145
- } else {
146
- _chunkZ2WQB55Rjs.writeDebug.call(void 0,
147
- `No existing items to delete in the R2 bucket path ${bucketPath}`
148
- );
149
- }
150
- } else {
151
- _chunkZ2WQB55Rjs.writeWarning.call(void 0, "[Dry run]: Skipping R2 bucket clean.");
152
- }
153
- }
154
- if (options.writeMetaJson === true) {
155
- const meta = {
156
- name: context.projectName,
157
- version,
158
- release,
159
- description: _optionalChain([projectDetails, 'optionalAccess', _18 => _18.content, 'optionalAccess', _19 => _19.description]),
160
- tags: _optionalChain([projectDetails, 'optionalAccess', _20 => _20.content, 'optionalAccess', _21 => _21.keywords]),
161
- dependencies,
162
- devDependencies: null,
163
- internalDependencies: internalDependencies.filter(
164
- (projectNode) => projectNode.data.tags && projectNode.data.tags.some(
165
- (tag) => tag.toLowerCase() === "component"
166
- )
167
- ).map((dep) => dep.name)
168
- };
169
- if (_optionalChain([projectDetails, 'optionalAccess', _22 => _22.type]) === "package.json") {
170
- meta.devDependencies = _optionalChain([projectDetails, 'optionalAccess', _23 => _23.content, 'optionalAccess', _24 => _24.devDependencies]);
171
- }
172
- await _chunkZWHJ35F5js.uploadFile.call(void 0,
173
- client,
174
- bucketId,
175
- bucketPath,
176
- "meta.json",
177
- version,
178
- JSON.stringify(meta),
179
- "application/json",
180
- isDryRun
181
- );
182
- }
183
- await Promise.all(
184
- files.map(async (file) => {
185
- if (_optionalChain([_fs.statSync.call(void 0, file, {
186
- throwIfNoEntry: false
187
- }), 'optionalAccess', _25 => _25.isFile, 'call', _26 => _26()])) {
188
- const name = _chunkZ2WQB55Rjs.correctPaths.call(void 0, file).replace(_chunkZ2WQB55Rjs.correctPaths.call(void 0, basePath), "");
189
- const type = _mimetypes2.default.lookup(name) || "application/octet-stream";
190
- await _chunkZWHJ35F5js.uploadFile.call(void 0,
191
- client,
192
- bucketId,
193
- bucketPath,
194
- name,
195
- version,
196
- type === "application/json" || type.includes("text") ? await _promises.readFile.call(void 0, file, "utf8") : `data:${type};base64,${Buffer.from(
197
- await _promises.readFile.call(void 0, file, "binary"),
198
- "binary"
199
- ).toString("base64")}`,
200
- type,
201
- isDryRun
202
- );
203
- }
204
- })
205
- );
206
- _chunkZ2WQB55Rjs.writeSuccess.call(void 0,
207
- `Successfully uploaded the ${projectName} project to the Cloudflare R2 bucket.`,
208
- config
209
- );
210
- return {
211
- success: true
212
- };
213
- } catch (error) {
214
- console.error("Failed to publish to Cloudflare R2 bucket");
215
- console.error(error);
216
- console.log("");
217
- return {
218
- success: false
219
- };
220
- }
221
- }
222
-
223
-
224
-
225
- exports.runExecutor = runExecutor;
@@ -1,52 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
-
3
-
4
-
5
- var _chunkZ2WQB55Rjs = require('./chunk-Z2WQB55R.js');
6
-
7
- // src/utils/r2-bucket-helpers.ts
8
- var _crypto = require('crypto');
9
- async function uploadFile(client, bucketName, bucketPath, fileName, version, fileContent, contentType = "application/octet-stream", isDryRun = false) {
10
- const key = _optionalChain([(!_optionalChain([bucketPath, 'optionalAccess', _ => _.trim, 'call', _2 => _2()]) || _optionalChain([bucketPath, 'optionalAccess', _3 => _3.trim, 'call', _4 => _4()]) === "/" ? fileName : _chunkZ2WQB55Rjs.joinPaths.call(void 0, bucketPath.trim(), fileName)), 'optionalAccess', _5 => _5.replace, 'call', _6 => _6(/^\/+/g, "")]) || "";
11
- _chunkZ2WQB55Rjs.writeDebug.call(void 0,
12
- `Uploading ${key} (content-type: ${contentType}) to the ${bucketName} R2 bucket`
13
- );
14
- if (!isDryRun) {
15
- await client.putObject(
16
- {
17
- Bucket: bucketName,
18
- Key: key,
19
- Body: fileContent,
20
- ContentType: contentType,
21
- Metadata: {
22
- version,
23
- checksum: _crypto.createHash.call(void 0, "sha256").update(fileContent).digest("base64")
24
- }
25
- },
26
- {
27
- requestTimeout: 15 * 60 * 1e3
28
- // 15 minutes
29
- }
30
- );
31
- } else {
32
- _chunkZ2WQB55Rjs.writeWarning.call(void 0, "[Dry run]: Skipping upload to the R2 bucket.");
33
- }
34
- }
35
- function getInternalDependencies(projectName, graph) {
36
- const allDeps = _nullishCoalesce(graph.dependencies[projectName], () => ( []));
37
- return Array.from(
38
- allDeps.reduce(
39
- (acc, node) => {
40
- const found = graph.nodes[node.target];
41
- if (found) acc.push(found);
42
- return acc;
43
- },
44
- []
45
- )
46
- );
47
- }
48
-
49
-
50
-
51
-
52
- exports.uploadFile = uploadFile; exports.getInternalDependencies = getInternalDependencies;