Skip to content

Commit

Permalink
chore: ensure published files can be executed on Deno; closes #734
Browse files Browse the repository at this point in the history
  • Loading branch information
pateketrueke committed Jan 3, 2023
1 parent 1b7d7d2 commit a02691a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 26 deletions.
8 changes: 8 additions & 0 deletions index.js
@@ -0,0 +1,8 @@
import $RefParser from 'json-schema-ref-parser';
import { JSONPath } from 'jsonpath-plus';

import { setDependencies } from './dist/shared.js';

setDependencies({ JSONPath, $RefParser });

export { default, JSONSchemaFaker } from './dist/shared.js';
8 changes: 6 additions & 2 deletions package.json
Expand Up @@ -11,11 +11,14 @@
"main": "dist/index.cjs",
"module": "dist/main.mjs",
"browser": "dist/main.iife.js",
"unpkg": "dist/bundle.cjs",
"unpkg": "dist/bundle.js",
"exports": {
".": {
"import": "./dist/main.mjs",
"require": "./dist/main.cjs"
},
"./esm": {
"import": "./index.js"
}
},
"scripts": {
Expand Down Expand Up @@ -55,7 +58,8 @@
"**/*.{cjs,mjs}.js:{filename}"
],
"bundle": [
"**/main*.js",
"**/main.*.js",
"**/shared.js",
"**/app.js"
],
"external": [
Expand Down
2 changes: 1 addition & 1 deletion src/main.cjs.js
@@ -1,4 +1,4 @@
const jsf = require('./lib/main.mjs').default;
const jsf = require('./shared').default;

module.exports = jsf;
module.exports.JSONSchemaFaker = { ...jsf };
11 changes: 5 additions & 6 deletions src/main.iife.js
Expand Up @@ -15,17 +15,16 @@
---
*/

const { setDependencies } = require('./lib/vendor');
const JSONSchemaFaker = require('./lib').default;
const jsf = require('./shared');

if (typeof window !== 'undefined') {
setDependencies({
jsf.setDependencies({
...window.JSONPath,
$RefParser: window.$RefParser,
});

window.JSONSchemaFaker = JSONSchemaFaker;
window.JSONSchemaFaker = jsf.default;
}

module.exports = JSONSchemaFaker;
module.exports.JSONSchemaFaker = JSONSchemaFaker;
module.exports = jsf.default;
module.exports.JSONSchemaFaker = jsf.JSONSchemaFaker;
14 changes: 14 additions & 0 deletions src/main.mjs
@@ -0,0 +1,14 @@
if (typeof process !== 'undefined') {
global.location = { href: `${process.cwd()}/` };
}

import './vendor.js';

import { setDependencies } from './shared.js';

/* global $RefParser, JSONPath */
if (typeof $RefParser !== 'undefined' && typeof JSONPath !== 'undefined') {
setDependencies({ ...JSONPath, $RefParser });
}

export { default, JSONSchemaFaker } from './shared.js';
17 changes: 0 additions & 17 deletions src/main.mjs.js

This file was deleted.

2 changes: 2 additions & 0 deletions src/shared.js
@@ -0,0 +1,2 @@
export { setDependencies } from './lib/vendor.mjs';
export { default, JSONSchemaFaker } from './lib/index.mjs';

0 comments on commit a02691a

Please sign in to comment.