@ttoss/cloudformation 0.9.5 → 0.9.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/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
2
 
3
3
  // src/findAndReadCloudFormationTemplate.ts
4
- import * as fs3 from "fs";
4
+ import * as fs2 from "fs";
5
5
  import * as path2 from "path";
6
6
 
7
7
  // src/readCloudFormationYamlTemplate.ts
@@ -161,80 +161,32 @@ var readCloudFormationYamlTemplate = ({
161
161
  return parsed;
162
162
  };
163
163
 
164
- // src/readObjectFile.ts
165
- import { createRequire } from "node:module";
166
- import { register } from "ts-node";
167
- import fs2 from "fs";
168
- import yaml2 from "js-yaml";
169
- var readYaml = ({
170
- path: path3
171
- }) => {
172
- const template = fs2.readFileSync(path3, "utf8") || JSON.stringify({});
173
- return yaml2.load(template);
174
- };
175
- var readObjectFile = ({
176
- path: path3
177
- }) => {
178
- if (!fs2.existsSync(path3)) {
179
- return {};
180
- }
181
- const require2 = createRequire(require('url').pathToFileURL(__filename).toString());
182
- const extension = path3.split(".").pop();
183
- if (extension === "ts") {
184
- register({
185
- compilerOptions: {
186
- moduleResolution: "node",
187
- module: "commonjs"
188
- },
189
- moduleTypes: {
190
- "carlin.*": "cjs"
191
- },
192
- transpileOnly: true
193
- });
194
- const tsObj = require2(path3);
195
- const obj = tsObj.default || tsObj;
196
- return typeof obj === "function" ? obj() : obj;
197
- }
198
- if (extension === "js") {
199
- const obj = require2(path3);
200
- return typeof obj === "function" ? obj() : obj;
201
- }
202
- if (extension === "json") {
203
- return require2(path3);
204
- }
205
- if (extension === "yml" || extension === "yaml") {
206
- return readYaml({
207
- path: path3
208
- });
209
- }
210
- return {};
211
- };
212
-
213
164
  // src/findAndReadCloudFormationTemplate.ts
165
+ import { readConfigFile } from "@ttoss/read-config-file";
214
166
  var defaultTemplatePaths = ["ts", "js", "yaml", "yml", "json"].map(extension => {
215
167
  return `./src/cloudformation.${extension}`;
216
168
  });
217
- var findAndReadCloudFormationTemplate = ({
169
+ var findAndReadCloudFormationTemplate = async ({
218
170
  templatePath: defaultTemplatePath
219
171
  }) => {
220
172
  const templatePath = defaultTemplatePath || defaultTemplatePaths.reduce((acc, cur) => {
221
173
  if (acc) {
222
174
  return acc;
223
175
  }
224
- return fs3.existsSync(path2.resolve(process.cwd(), cur)) ? cur : acc;
176
+ return fs2.existsSync(path2.resolve(process.cwd(), cur)) ? cur : acc;
225
177
  }, "");
226
178
  if (!templatePath) {
227
179
  throw new Error("Cannot find a CloudFormation template.");
228
180
  }
229
181
  const extension = templatePath?.split(".").pop();
230
- const fullPath = path2.resolve(process.cwd(), templatePath);
231
182
  if (["yaml", "yml"].includes(extension)) {
232
183
  return readCloudFormationYamlTemplate({
233
184
  templatePath
234
185
  });
235
186
  }
236
- return readObjectFile({
237
- path: fullPath
187
+ const configFilePath = path2.resolve(process.cwd(), templatePath);
188
+ return readConfigFile({
189
+ configFilePath
238
190
  });
239
191
  };
240
- export { findAndReadCloudFormationTemplate, readObjectFile as unstable_readObjectFile };
192
+ export { findAndReadCloudFormationTemplate };
@@ -78,10 +78,6 @@ type CloudFormationTemplate = {
78
78
 
79
79
  declare const findAndReadCloudFormationTemplate: ({ templatePath: defaultTemplatePath, }: {
80
80
  templatePath?: string;
81
- }) => CloudFormationTemplate;
81
+ }) => Promise<CloudFormationTemplate>;
82
82
 
83
- declare const readObjectFile: ({ path }: {
84
- path: string;
85
- }) => any;
86
-
87
- export { type CloudFormationTemplate, type IAMRoleResource, type Output, type Outputs, type Parameter, type Parameters, type Policy, type Resource, type Resources, findAndReadCloudFormationTemplate, readObjectFile as unstable_readObjectFile };
83
+ export { type CloudFormationTemplate, type IAMRoleResource, type Output, type Outputs, type Parameter, type Parameters, type Policy, type Resource, type Resources, findAndReadCloudFormationTemplate };
package/dist/index.d.ts CHANGED
@@ -78,10 +78,6 @@ type CloudFormationTemplate = {
78
78
 
79
79
  declare const findAndReadCloudFormationTemplate: ({ templatePath: defaultTemplatePath, }: {
80
80
  templatePath?: string;
81
- }) => CloudFormationTemplate;
81
+ }) => Promise<CloudFormationTemplate>;
82
82
 
83
- declare const readObjectFile: ({ path }: {
84
- path: string;
85
- }) => any;
86
-
87
- export { type CloudFormationTemplate, type IAMRoleResource, type Output, type Outputs, type Parameter, type Parameters, type Policy, type Resource, type Resources, findAndReadCloudFormationTemplate, readObjectFile as unstable_readObjectFile };
83
+ export { type CloudFormationTemplate, type IAMRoleResource, type Output, type Outputs, type Parameter, type Parameters, type Policy, type Resource, type Resources, findAndReadCloudFormationTemplate };
package/dist/index.js CHANGED
@@ -38,21 +38,20 @@ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
38
38
  // src/index.ts
39
39
  var src_exports = {};
40
40
  __export(src_exports, {
41
- findAndReadCloudFormationTemplate: () => findAndReadCloudFormationTemplate,
42
- unstable_readObjectFile: () => readObjectFile
41
+ findAndReadCloudFormationTemplate: () => findAndReadCloudFormationTemplate
43
42
  });
44
43
  module.exports = __toCommonJS(src_exports);
45
44
 
46
45
  // src/findAndReadCloudFormationTemplate.ts
47
- var fs3 = __toESM(require("fs"));
48
- var path2 = __toESM(require("path"));
46
+ var fs2 = __toESM(require("fs"), 1);
47
+ var path2 = __toESM(require("path"), 1);
49
48
 
50
49
  // src/readCloudFormationYamlTemplate.ts
51
- var fs = __toESM(require("fs"));
52
- var path = __toESM(require("path"));
50
+ var fs = __toESM(require("fs"), 1);
51
+ var path = __toESM(require("path"), 1);
53
52
 
54
53
  // src/cloudFormationYamlTemplate.ts
55
- var import_js_yaml = __toESM(require("js-yaml"));
54
+ var import_js_yaml = __toESM(require("js-yaml"), 1);
56
55
  var cloudFormationTypes = [{
57
56
  tag: "!Equals",
58
57
  options: {
@@ -204,85 +203,35 @@ var readCloudFormationYamlTemplate = ({
204
203
  return parsed;
205
204
  };
206
205
 
207
- // src/readObjectFile.ts
208
- var import_node_module = require("module");
209
- var import_ts_node = require("ts-node");
210
- var import_fs = __toESM(require("fs"));
211
- var import_js_yaml2 = __toESM(require("js-yaml"));
212
- var import_meta = {};
213
- var readYaml = ({
214
- path: path3
215
- }) => {
216
- const template = import_fs.default.readFileSync(path3, "utf8") || JSON.stringify({});
217
- return import_js_yaml2.default.load(template);
218
- };
219
- var readObjectFile = ({
220
- path: path3
221
- }) => {
222
- if (!import_fs.default.existsSync(path3)) {
223
- return {};
224
- }
225
- const require2 = (0, import_node_module.createRequire)(import_meta.url);
226
- const extension = path3.split(".").pop();
227
- if (extension === "ts") {
228
- (0, import_ts_node.register)({
229
- compilerOptions: {
230
- moduleResolution: "node",
231
- module: "commonjs"
232
- },
233
- moduleTypes: {
234
- "carlin.*": "cjs"
235
- },
236
- transpileOnly: true
237
- });
238
- const tsObj = require2(path3);
239
- const obj = tsObj.default || tsObj;
240
- return typeof obj === "function" ? obj() : obj;
241
- }
242
- if (extension === "js") {
243
- const obj = require2(path3);
244
- return typeof obj === "function" ? obj() : obj;
245
- }
246
- if (extension === "json") {
247
- return require2(path3);
248
- }
249
- if (extension === "yml" || extension === "yaml") {
250
- return readYaml({
251
- path: path3
252
- });
253
- }
254
- return {};
255
- };
256
-
257
206
  // src/findAndReadCloudFormationTemplate.ts
207
+ var import_read_config_file = require("@ttoss/read-config-file");
258
208
  var defaultTemplatePaths = ["ts", "js", "yaml", "yml", "json"].map(extension => {
259
209
  return `./src/cloudformation.${extension}`;
260
210
  });
261
- var findAndReadCloudFormationTemplate = ({
211
+ var findAndReadCloudFormationTemplate = async ({
262
212
  templatePath: defaultTemplatePath
263
213
  }) => {
264
214
  const templatePath = defaultTemplatePath || defaultTemplatePaths.reduce((acc, cur) => {
265
215
  if (acc) {
266
216
  return acc;
267
217
  }
268
- return fs3.existsSync(path2.resolve(process.cwd(), cur)) ? cur : acc;
218
+ return fs2.existsSync(path2.resolve(process.cwd(), cur)) ? cur : acc;
269
219
  }, "");
270
220
  if (!templatePath) {
271
221
  throw new Error("Cannot find a CloudFormation template.");
272
222
  }
273
223
  const extension = templatePath?.split(".").pop();
274
- const fullPath = path2.resolve(process.cwd(), templatePath);
275
224
  if (["yaml", "yml"].includes(extension)) {
276
225
  return readCloudFormationYamlTemplate({
277
226
  templatePath
278
227
  });
279
228
  }
280
- return readObjectFile({
281
- path: fullPath
229
+ const configFilePath = path2.resolve(process.cwd(), templatePath);
230
+ return (0, import_read_config_file.readConfigFile)({
231
+ configFilePath
282
232
  });
283
233
  };
284
234
  // Annotate the CommonJS export names for ESM import in node:
285
235
  0 && (module.exports = {
286
- findAndReadCloudFormationTemplate,
287
- unstable_readObjectFile
236
+ findAndReadCloudFormationTemplate
288
237
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/cloudformation",
3
- "version": "0.9.5",
3
+ "version": "0.9.7",
4
4
  "description": "CloudFormation utils.",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -11,10 +11,10 @@
11
11
  "url": "https://github.com/ttoss/ttoss.git",
12
12
  "directory": "packages/cloudformation"
13
13
  },
14
+ "type": "module",
14
15
  "exports": {
15
16
  ".": {
16
17
  "import": "./dist/esm/index.js",
17
- "require": "./dist/index.js",
18
18
  "types": "./dist/index.d.ts"
19
19
  }
20
20
  },
@@ -24,7 +24,7 @@
24
24
  ],
25
25
  "dependencies": {
26
26
  "js-yaml": "^4.1.0",
27
- "ts-node": "^10.9.2"
27
+ "@ttoss/read-config-file": "^1.0.2"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/jest": "^29.5.12",
@@ -32,8 +32,8 @@
32
32
  "@types/node": "^20.12.7",
33
33
  "jest": "^29.7.0",
34
34
  "tsup": "^8.0.2",
35
- "@ttoss/config": "^1.32.2",
36
- "@ttoss/test-utils": "^2.1.5"
35
+ "@ttoss/test-utils": "^2.1.6",
36
+ "@ttoss/config": "^1.32.3"
37
37
  },
38
38
  "keywords": [],
39
39
  "publishConfig": {
@@ -2,7 +2,7 @@ import * as fs from 'fs';
2
2
  import * as path from 'path';
3
3
  import { CloudFormationTemplate } from './CloudFormationTemplate';
4
4
  import { readCloudFormationYamlTemplate } from './readCloudFormationYamlTemplate';
5
- import { readObjectFile } from './readObjectFile';
5
+ import { readConfigFile } from '@ttoss/read-config-file';
6
6
 
7
7
  export const defaultTemplatePaths = ['ts', 'js', 'yaml', 'yml', 'json'].map(
8
8
  (extension) => {
@@ -10,11 +10,11 @@ export const defaultTemplatePaths = ['ts', 'js', 'yaml', 'yml', 'json'].map(
10
10
  }
11
11
  );
12
12
 
13
- export const findAndReadCloudFormationTemplate = ({
13
+ export const findAndReadCloudFormationTemplate = async ({
14
14
  templatePath: defaultTemplatePath,
15
15
  }: {
16
16
  templatePath?: string;
17
- }): CloudFormationTemplate => {
17
+ }): Promise<CloudFormationTemplate> => {
18
18
  const templatePath =
19
19
  defaultTemplatePath ||
20
20
  defaultTemplatePaths
@@ -37,8 +37,6 @@ export const findAndReadCloudFormationTemplate = ({
37
37
 
38
38
  const extension = templatePath?.split('.').pop() as string;
39
39
 
40
- const fullPath = path.resolve(process.cwd(), templatePath);
41
-
42
40
  /**
43
41
  * We need to read Yaml first because CloudFormation specific tags aren't
44
42
  * recognized when parsing a simple Yaml file. I.e., a possible error:
@@ -48,5 +46,7 @@ export const findAndReadCloudFormationTemplate = ({
48
46
  return readCloudFormationYamlTemplate({ templatePath });
49
47
  }
50
48
 
51
- return readObjectFile({ path: fullPath });
49
+ const configFilePath = path.resolve(process.cwd(), templatePath);
50
+
51
+ return readConfigFile({ configFilePath });
52
52
  };
package/src/index.ts CHANGED
@@ -1,7 +1,2 @@
1
1
  export { findAndReadCloudFormationTemplate } from './findAndReadCloudFormationTemplate';
2
2
  export * from './CloudFormationTemplate';
3
-
4
- /**
5
- * Unstable API.
6
- */
7
- export { readObjectFile as unstable_readObjectFile } from './readObjectFile';
@@ -1,49 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-var-requires */
2
- import { createRequire } from 'node:module';
3
- import { register } from 'ts-node';
4
- import fs from 'fs';
5
- import yaml from 'js-yaml';
6
-
7
- export const readYaml = ({ path }: { path: string }) => {
8
- const template = fs.readFileSync(path, 'utf8') || JSON.stringify({});
9
- return yaml.load(template);
10
- };
11
-
12
- export const readObjectFile = ({ path }: { path: string }) => {
13
- if (!fs.existsSync(path)) {
14
- return {};
15
- }
16
-
17
- const require = createRequire(import.meta.url);
18
-
19
- const extension = path.split('.').pop();
20
-
21
- if (extension === 'ts') {
22
- register({
23
- compilerOptions: { moduleResolution: 'node', module: 'commonjs' },
24
- moduleTypes: {
25
- 'carlin.*': 'cjs',
26
- },
27
- transpileOnly: true,
28
- });
29
-
30
- const tsObj = require(path);
31
- const obj = tsObj.default || tsObj;
32
- return typeof obj === 'function' ? obj() : obj;
33
- }
34
-
35
- if (extension === 'js') {
36
- const obj = require(path);
37
- return typeof obj === 'function' ? obj() : obj;
38
- }
39
-
40
- if (extension === 'json') {
41
- return require(path);
42
- }
43
-
44
- if (extension === 'yml' || extension === 'yaml') {
45
- return readYaml({ path });
46
- }
47
-
48
- return {};
49
- };