@mediatool/frontend-tools 1.3.0 → 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 +35 -16
- package/lib/build/get-module-context.js +32 -16
- package/lib/test/dom-shims.cjs +14 -0
- package/lib/test/index.js +3 -0
- package/package.json +2 -2
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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,6 +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');
|
|
87
|
+
const domShimsPath = require$1.resolve('@mediatool/frontend-tools/lib/test/dom-shims.cjs');
|
|
71
88
|
|
|
72
89
|
const extensions = '{js,jsx,ts,tsx}';
|
|
73
90
|
const types = {
|
|
@@ -85,6 +102,8 @@ async function test (typeOrSpec) {
|
|
|
85
102
|
spec,
|
|
86
103
|
'--require',
|
|
87
104
|
'global-jsdom/register',
|
|
105
|
+
'--require',
|
|
106
|
+
domShimsPath,
|
|
88
107
|
];
|
|
89
108
|
|
|
90
109
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
if (typeof window !== 'undefined' && !window.matchMedia) {
|
|
2
|
+
window.matchMedia = function(query) {
|
|
3
|
+
return {
|
|
4
|
+
matches: false,
|
|
5
|
+
media: query,
|
|
6
|
+
onchange: null,
|
|
7
|
+
addListener: function () {},
|
|
8
|
+
removeListener: function() {},
|
|
9
|
+
addEventListener: function() {},
|
|
10
|
+
removeEventListener: function() {},
|
|
11
|
+
dispatchEvent: function() { return true; }
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
}
|
package/lib/test/index.js
CHANGED
|
@@ -3,6 +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
7
|
|
|
7
8
|
const extensions = '{js,jsx,ts,tsx}'
|
|
8
9
|
const types = {
|
|
@@ -20,6 +21,8 @@ export default async function test (typeOrSpec) {
|
|
|
20
21
|
spec,
|
|
21
22
|
'--require',
|
|
22
23
|
'global-jsdom/register',
|
|
24
|
+
'--require',
|
|
25
|
+
domShimsPath,
|
|
23
26
|
]
|
|
24
27
|
|
|
25
28
|
const mochaProcess = spawn(process.execPath, args, { stdio: 'inherit' })
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mediatool/frontend-tools",
|
|
3
|
-
"version": "1.3.
|
|
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",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
".": "./dist/utils.js",
|
|
10
10
|
"./assertions": "./dist/assertions.js",
|
|
11
11
|
"./react": "./dist/react.js",
|
|
12
|
-
"./lib/test/
|
|
12
|
+
"./lib/test/dom-shims.cjs": "./lib/test/dom-shims.cjs"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "rm -rf dist && rollup -c rollup.config.js",
|