@mediatool/frontend-tools 1.3.1 → 1.3.2

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/mtft.cjs CHANGED
@@ -9,25 +9,41 @@ var ramda = require('ramda');
9
9
  var module$1 = require('module');
10
10
  var child_process = require('child_process');
11
11
 
12
+ async function fileExists (location) {
13
+ return promises.stat(location)
14
+ .then(() => true)
15
+ .catch(() => false)
16
+ }
17
+
18
+ async function getEntryFileLocation (moduleRootLocation) {
19
+ const jsLocation = path.resolve(moduleRootLocation, './index.js');
20
+ const tsLocation = path.resolve(moduleRootLocation, './index.ts');
21
+
22
+ const [ jsFileExists, tsFileExists ] = await Promise.all([
23
+ fileExists(jsLocation),
24
+ fileExists(tsLocation),
25
+ ]);
26
+
27
+ if (tsFileExists) return tsLocation
28
+ if (jsFileExists) return jsLocation
29
+
30
+ throw new Error('Cannot find module\'s entrypoint. Create an index.js/ts at the root of the module and try again.')
31
+ }
32
+
12
33
  async function getModuleContext () {
13
34
  const location = process.cwd();
14
35
  const pkgLocation = path.resolve(location, './package.json');
15
- const entryLocation = path.resolve(location, './index.js');
16
-
17
- try {
18
- await promises.stat(pkgLocation);
19
- await promises.stat(entryLocation);
20
- const pkg = JSON.parse(await promises.readFile(pkgLocation));
21
- const { name } = pkg;
22
- const dependencies = ramda.uniq(ramda.keys({ ...pkg.dependencies, ...pkg.peerDependencies }));
23
- return {
24
- entry: entryLocation,
25
- root: location,
26
- name,
27
- dependencies,
28
- }
29
- } catch (e) {
30
- throw new Error('Oopsie.')
36
+
37
+ await promises.stat(pkgLocation);
38
+ const entryLocation = await getEntryFileLocation(location);
39
+ const pkg = JSON.parse(await promises.readFile(pkgLocation));
40
+ const { name } = pkg;
41
+ const dependencies = ramda.uniq(ramda.keys({ ...pkg.dependencies, ...pkg.peerDependencies }));
42
+ return {
43
+ entry: entryLocation,
44
+ root: location,
45
+ name,
46
+ dependencies,
31
47
  }
32
48
  }
33
49
 
@@ -3,25 +3,41 @@ import { resolve } from 'path'
3
3
  // eslint-disable-next-line import/no-extraneous-dependencies
4
4
  import { keys, uniq } from 'ramda'
5
5
 
6
+ async function fileExists (location) {
7
+ return stat(location)
8
+ .then(() => true)
9
+ .catch(() => false)
10
+ }
11
+
12
+ async function getEntryFileLocation (moduleRootLocation) {
13
+ const jsLocation = resolve(moduleRootLocation, './index.js')
14
+ const tsLocation = resolve(moduleRootLocation, './index.ts')
15
+
16
+ const [ jsFileExists, tsFileExists ] = await Promise.all([
17
+ fileExists(jsLocation),
18
+ fileExists(tsLocation),
19
+ ])
20
+
21
+ if (tsFileExists) return tsLocation
22
+ if (jsFileExists) return jsLocation
23
+
24
+ throw new Error('Cannot find module\'s entrypoint. Create an index.js/ts at the root of the module and try again.')
25
+ }
26
+
6
27
  async function getModuleContext () {
7
28
  const location = process.cwd()
8
29
  const pkgLocation = resolve(location, './package.json')
9
- const entryLocation = resolve(location, './index.js')
10
-
11
- try {
12
- await stat(pkgLocation)
13
- await stat(entryLocation)
14
- const pkg = JSON.parse(await readFile(pkgLocation))
15
- const { name } = pkg
16
- const dependencies = uniq(keys({ ...pkg.dependencies, ...pkg.peerDependencies }))
17
- return {
18
- entry: entryLocation,
19
- root: location,
20
- name,
21
- dependencies,
22
- }
23
- } catch (e) {
24
- throw new Error('Oopsie.')
30
+
31
+ await stat(pkgLocation)
32
+ const entryLocation = await getEntryFileLocation(location)
33
+ const pkg = JSON.parse(await readFile(pkgLocation))
34
+ const { name } = pkg
35
+ const dependencies = uniq(keys({ ...pkg.dependencies, ...pkg.peerDependencies }))
36
+ return {
37
+ entry: entryLocation,
38
+ root: location,
39
+ name,
40
+ dependencies,
25
41
  }
26
42
  }
27
43
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mediatool/frontend-tools",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Common configs and tooling for bundling, testing, linting frontend modules",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",