Skip to content

Commit

Permalink
Improved WikiJS to support both commonjs and esm
Browse files Browse the repository at this point in the history
  • Loading branch information
richardvanderdys committed Feb 7, 2023
1 parent c274989 commit 79f22ec
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 25 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

11 changes: 11 additions & 0 deletions fixup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cat >dist/cjs/package.json <<!EOF
{
"type": "commonjs"
}
!EOF

cat >dist/mjs/package.json <<!EOF
{
"type": "module"
}
!EOF
26 changes: 15 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wikijs",
"description": "Mediawiki interface for Node and Web",
"author": "Richard van der Dys",
"version": "6.4.0",
"version": "6.4.1",
"keywords": [
"wiki",
"wikipedia",
Expand All @@ -18,7 +18,6 @@
"engines": {
"node": ">=0.10.4"
},
"main": "./dist/wiki.js",
"funding": {
"type": "individual",
"url": "https://www.buymeacoffee.com/2tmRKi9"
Expand All @@ -32,26 +31,22 @@
"@pollyjs/adapter-node-http": "^2.5.0",
"@pollyjs/core": "^2.5.0",
"@pollyjs/persister-fs": "^2.1.0",
"babel": "^6.23.0",
"babel-cli": "^6.24.0",
"babel-preset-babili": "0.0.12",
"babel-preset-latest": "^6.24.0",
"babel-register": "^6.24.0",
"coveralls": "^2.11.9",
"eslint": "^4.19.1",
"gh-pages": "^1.0.0",
"istanbul": "^1.0.0-alpha.2",
"jsdoc": "^3.3.0-beta3",
"minami": "^1.1.0",
"mocha": "^2.5.3",
"mocha": "^10.2.0",
"nock": "^10.0.2",
"prettier": "1.15.3",
"should": "^9.0.0"
"should": "^9.0.0",
"typescript": "^4.9.5"
},
"typings": "./index.d.ts",
"scripts": {
"build": "babel src --out-dir dist --source-maps true",
"test": "node_modules/.bin/_mocha --no-colors --compilers js:babel-register",
"build": "rm -fr dist/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && bash fixup.sh",
"test": "mocha",
"cover": "babel-node ./node_modules/istanbul/lib/cli cover node_modules/.bin/_mocha",
"docs": "node_modules/.bin/jsdoc --configure .jsdoc.json --verbose",
"lint": "eslint src",
Expand All @@ -66,5 +61,14 @@
},
"publishConfig": {
"access": "public"
},
"type": "module",
"main": "dist/cjs/wiki.js",
"module": "dist/mjs/wiki.js",
"exports": {
".": {
"import": "./dist/mjs/wiki.js",
"require": "./dist/cjs/wiki.js"
}
}
}
2 changes: 1 addition & 1 deletion src/chain.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { api } from './util';
import { api } from './util.js';

const processors = {
extracts: data => {
Expand Down
6 changes: 3 additions & 3 deletions src/page.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { aggregatePagination, pagination, api, parseContent } from './util';
import infoboxParser from 'infobox-parser';
import { tokenize, constructTree } from 'hyntax';
import { parseCoordinates } from './coordinates';
import QueryChain from './chain';
import { aggregatePagination, pagination, api, parseContent } from './util.js';
import { parseCoordinates } from './coordinates.js';
import QueryChain from './chain.js';

const get = (obj, first, ...rest) => {
if (obj === undefined || first === undefined) return obj;
Expand Down
6 changes: 3 additions & 3 deletions src/wiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import fetch from 'cross-fetch';
import querystring from 'querystring';

import { pagination, api, aggregate } from './util';
import wikiPage from './page';
import QueryChain from './chain';
import { pagination, api, aggregate } from './util.js';
import wikiPage from './page.js';
import QueryChain from './chain.js';

/**
* @namespace
Expand Down
1 change: 0 additions & 1 deletion test/mocha.opts

This file was deleted.

4 changes: 2 additions & 2 deletions test/real.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import should from 'should';
import wiki from '../src/wiki';

import { Polly, setupMocha as setupPolly } from '@pollyjs/core';
import NodeHttpAdapter from '@pollyjs/adapter-node-http';
import FSPersister from '@pollyjs/persister-fs';

import wiki from '../src/wiki.js';

Polly.register(NodeHttpAdapter);
Polly.register(FSPersister);

Expand Down
3 changes: 2 additions & 1 deletion test/spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'should';
import wiki from '../src/wiki';

import { Polly, setupMocha as setupPolly } from '@pollyjs/core';
import NodeHttpAdapter from '@pollyjs/adapter-node-http';
import FSPersister from '@pollyjs/persister-fs';

import wiki from '../src/wiki.js';

Polly.register(NodeHttpAdapter);
Polly.register(FSPersister);

Expand Down
24 changes: 24 additions & 0 deletions tsconfig-base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "src",
"declaration": true,
"esModuleInterop": true,
"inlineSourceMap": false,
"lib": ["esnext"],
"listEmittedFiles": false,
"listFiles": false,
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"pretty": true,
"resolveJsonModule": true,
"rootDir": "src",
"skipLibCheck": true,
"strict": true,
"traceResolution": false,
},
"compileOnSave": false,
"exclude": ["node_modules", "dist"],
"include": ["src"]
}
8 changes: 8 additions & 0 deletions tsconfig-cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig-base.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "dist/cjs",
"target": "es2015"
}
}
8 changes: 8 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig-base.json",
"compilerOptions": {
"module": "esnext",
"outDir": "dist/mjs",
"target": "esnext"
}
}

0 comments on commit 79f22ec

Please sign in to comment.