@mediatool/frontend-tools 1.3.1 → 1.3.3

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
 
@@ -68,7 +84,7 @@ function build (type) {
68
84
 
69
85
  const require$1 = module$1.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('mtft.cjs', document.baseURI).href)));
70
86
  const mochaCliPath = require$1.resolve('mocha/lib/cli/cli.js');
71
- const domShimsPath = require$1.resolve('@mediatool/frontend-tools/lib/test/dom-shims.cjs');
87
+ const requireFilePath = require$1.resolve('@mediatool/frontend-tools/lib/test/require.cjs');
72
88
 
73
89
  const extensions = '{js,jsx,ts,tsx}';
74
90
  const types = {
@@ -85,9 +101,7 @@ async function test (typeOrSpec) {
85
101
  mochaCliPath,
86
102
  spec,
87
103
  '--require',
88
- 'global-jsdom/register',
89
- '--require',
90
- domShimsPath,
104
+ requireFilePath,
91
105
  ];
92
106
 
93
107
  const mochaProcess = child_process.spawn(process.execPath, args, { stdio: 'inherit' });
@@ -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/lib/test/index.js CHANGED
@@ -3,7 +3,7 @@ import { spawn } from 'child_process'
3
3
 
4
4
  const require = createRequire(import.meta.url)
5
5
  const mochaCliPath = require.resolve('mocha/lib/cli/cli.js')
6
- const domShimsPath = require.resolve('@mediatool/frontend-tools/lib/test/dom-shims.cjs')
6
+ const requireFilePath = require.resolve('@mediatool/frontend-tools/lib/test/require.cjs')
7
7
 
8
8
  const extensions = '{js,jsx,ts,tsx}'
9
9
  const types = {
@@ -20,9 +20,7 @@ export default async function test (typeOrSpec) {
20
20
  mochaCliPath,
21
21
  spec,
22
22
  '--require',
23
- 'global-jsdom/register',
24
- '--require',
25
- domShimsPath,
23
+ requireFilePath,
26
24
  ]
27
25
 
28
26
  const mochaProcess = spawn(process.execPath, args, { stdio: 'inherit' })
@@ -1,5 +1,7 @@
1
+ require('global-jsdom/register')
2
+
1
3
  if (typeof window !== 'undefined' && !window.matchMedia) {
2
- window.matchMedia = function(query) {
4
+ window.matchMedia = function (query) {
3
5
  return {
4
6
  matches: false,
5
7
  media: query,
@@ -8,7 +10,11 @@ if (typeof window !== 'undefined' && !window.matchMedia) {
8
10
  removeListener: function() {},
9
11
  addEventListener: function() {},
10
12
  removeEventListener: function() {},
11
- dispatchEvent: function() { return true; }
12
- };
13
- };
13
+ dispatchEvent: function() { return true },
14
+ }
15
+ }
14
16
  }
17
+
18
+ require.extensions['.css'] = function () {
19
+ return undefined
20
+ }
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.3",
4
4
  "description": "Common configs and tooling for bundling, testing, linting frontend modules",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -9,7 +9,7 @@
9
9
  ".": "./dist/utils.js",
10
10
  "./assertions": "./dist/assertions.js",
11
11
  "./react": "./dist/react.js",
12
- "./lib/test/dom-shims.cjs": "./lib/test/dom-shims.cjs"
12
+ "./lib/test/require.cjs": "./lib/test/require.cjs"
13
13
  },
14
14
  "scripts": {
15
15
  "build": "rm -rf dist && rollup -c rollup.config.js",