diff --git a/benchmark/engines/liquid.js b/benchmark/engines/liquid.js index eb623540b0..8bc871f39f 100644 --- a/benchmark/engines/liquid.js +++ b/benchmark/engines/liquid.js @@ -1,3 +1,3 @@ const { createEngine } = require('./create-liquid') -module.exports = createEngine(require('../../dist/liquid.node.cjs')) +module.exports = createEngine(require('../../dist/liquid.cjs')) diff --git a/bin/perf-diff.sh b/bin/perf-diff.sh index 25a1a9363a..98146ee5ef 100755 --- a/bin/perf-diff.sh +++ b/bin/perf-diff.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash VERSION_LATEST=$(cat package.json | grep '"version":' | head -1 | awk -F'"' '{print $4}') -FILE_LOCAL=dist/liquid.node.cjs.js -FILE_LATEST=dist/liquid.node.cjs.$VERSION_LATEST.js -URL_LATEST=https://unpkg.com/liquidjs@$VERSION_LATEST/dist/liquid.node.cjs.js +FILE_LOCAL=dist/liquid.node.js +FILE_LATEST=dist/liquid.node.$VERSION_LATEST.js +URL_LATEST=https://unpkg.com/liquidjs@$VERSION_LATEST/dist/liquid.node.js if [ ! -f "$FILE_LATEST" ]; then curl $URL_LATEST > $FILE_LATEST diff --git a/package.json b/package.json index e44275df3c..9a056b4e6a 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,16 @@ "name": "liquidjs", "version": "10.16.4", "description": "A simple, expressive and safe Shopify / Github Pages compatible template engine in pure JavaScript.", - "main": "dist/liquid.node.cjs.js", - "module": "dist/liquid.node.esm.js", - "es2015": "dist/liquid.browser.esm.js", + "main": "dist/liquid.node.js", + "module": "dist/liquid.node.mjs", + "es2015": "dist/liquid.browser.mjs", "browser": { - "./dist/liquid.node.cjs.js": "./dist/liquid.browser.umd.js", - "./dist/liquid.node.esm.js": "./dist/liquid.browser.esm.js" + "./dist/liquid.node.js": "./dist/liquid.browser.umd.js", + "./dist/liquid.node.mjs": "./dist/liquid.browser.mjs" + }, + "exports": { + "import": "./dist/liquid.node.mjs", + "require": "./dist/liquid.node.js" }, "types": "dist/index.d.ts", "engines": { @@ -19,6 +23,7 @@ "test": "jest", "test:coverage": "jest --coverage src test/integration", "test:e2e": "jest test/e2e", + "test:demo": "./test/demo/check.sh", "perf:diff": "bin/perf-diff.sh", "perf:engines": "cd benchmark && npm run engines", "version": "npm run build && npm test", diff --git a/rollup.config.mjs b/rollup.config.mjs index 87b6edbce1..8d17634f8f 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -51,14 +51,14 @@ const browserStream = { './streamed-emitter': '../build/streamed-emitter-browser' } const esmRequire = { - include: './src/fs/node.ts', + include: './src/fs/fs-impl.ts', delimiters: ['', ''], './node-require': '../build/node-require.mjs' } const nodeCjs = { output: [{ - file: 'dist/liquid.node.cjs.js', + file: 'dist/liquid.node.js', format: 'cjs', banner }], @@ -70,7 +70,7 @@ const nodeCjs = { const nodeEsm = { output: [{ - file: 'dist/liquid.node.esm.js', + file: 'dist/liquid.node.mjs', format: 'esm', banner }], @@ -86,7 +86,7 @@ const nodeEsm = { const browserEsm = { output: [{ - file: 'dist/liquid.browser.esm.js', + file: 'dist/liquid.browser.mjs', format: 'esm', banner }], diff --git a/src/build/node-require.mjs b/src/build/node-require.mjs index 3933406075..b0e738b9d4 100644 --- a/src/build/node-require.mjs +++ b/src/build/node-require.mjs @@ -1,10 +1,6 @@ import { createRequire } from 'module' export function requireResolve (file) { - /** - * createRequire() can throw, - * when import.meta.url not begin with "file://". - */ - const require = createRequire(import.meta.url) + const require = createRequire(process.cwd() + '/') return require.resolve(file) } diff --git a/test/e2e/render-to-node-stream.spec.ts b/test/e2e/render-to-node-stream.spec.ts index 136daa3a21..edfc25fc5e 100644 --- a/test/e2e/render-to-node-stream.spec.ts +++ b/test/e2e/render-to-node-stream.spec.ts @@ -3,7 +3,7 @@ import { drainStream } from '../stub/stream' describe('.renderToNodeStream()', function () { it('should render to stream in Node.js', done => { - const cjs = require('../../dist/liquid.node.cjs') + const cjs = require('../../dist/liquid.node') const engine = new cjs.Liquid() const tpl = engine.parseFileSync(resolve(__dirname, '../stub/root/foo.html')) const stream = engine.renderToNodeStream(tpl) @@ -28,7 +28,7 @@ describe('.renderToNodeStream()', function () { describe('.renderFileToNodeStream()', function () { it('should render to stream in Node.js', async () => { - const cjs = require('../../dist/liquid.node.cjs') + const cjs = require('../../dist/liquid.node') const engine = new cjs.Liquid({ root: resolve(__dirname, '../stub/root/') })