Skip to content

Commit

Permalink
BREAKING: Provides dual ESM/CJS exports
Browse files Browse the repository at this point in the history
This change makes lib/get-transformer.js unavailable for import
  • Loading branch information
webketje committed Jul 2, 2023
1 parent 993f8ca commit cc84b5b
Show file tree
Hide file tree
Showing 8 changed files with 12,512 additions and 5,568 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ rules:
import/first: error
import/no-anonymous-default-export: error
import/no-unassigned-import: error
import/no-internal-modules: error
import/no-internal-modules:
- error
- allow:
- src/**
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ npm-debug.log*
coverage
coverage.info
test/fixtures/*/build
node_modules
node_modules
lib
!lib/*.d.ts
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test/fixtures/**
coverage/**
package-lock.json
package-lock.json
lib
18,023 changes: 12,473 additions & 5,550 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "@metalsmith/in-place",
"author": "ismay",
"description": "A metalsmith plugin for in-place templating",
"license": "MIT",
Expand All @@ -8,8 +9,14 @@
"metalsmith-plugin",
"metalsmith"
],
"main": "lib/index.js",
"name": "@metalsmith/in-place",
"source": "src/index.js",
"main": "lib/index.cjs",
"module": "lib/index.js",
"type": "module",
"exports": {
"import": "./lib/index.js",
"require": "./lib/index.cjs"
},
"repository": {
"type": "git",
"url": "https://github.com/metalsmith/in-place.git"
Expand All @@ -26,6 +33,8 @@
"format:check": "prettier --list-different \"**/*.{yml,md,js,json}\"",
"test": "c8 mocha",
"release": "release-it",
"build": "microbundle --target node -f cjs,esm --strict --generateTypes=false",
"prepack": "npm run build",
"lint": "eslint --fix .",
"lint:check": "eslint --fix-dry-run ."
},
Expand All @@ -42,6 +51,7 @@
"jstransformer-marked": "^1.2.0",
"jstransformer-pug": "^0.4.0",
"metalsmith": "^2.6.0",
"microbundle": "^0.15.1",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"prettier": "^2.8.8",
Expand Down
6 changes: 3 additions & 3 deletions lib/get-transformer.js → src/get-transformer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const jstransformer = require('jstransformer')
const toTransformer = require('inputformat-to-jstransformer')
import jstransformer from 'jstransformer'
import toTransformer from 'inputformat-to-jstransformer'

/**
* Gets jstransformer for an extension, and caches them
Expand All @@ -18,4 +18,4 @@ function getTransformer(ext) {
return cache[ext]
}

module.exports = getTransformer
export default getTransformer
9 changes: 5 additions & 4 deletions lib/index.js → src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require('path')
const isUtf8 = require('is-utf8')
const getTransformer = require('./get-transformer')
import path from 'node:path'
import isUtf8 from 'is-utf8'
import getTransformer from './get-transformer.js'

let debug = () => {
throw new Error('uninstantiated debug')
}
Expand Down Expand Up @@ -164,4 +165,4 @@ function initializeInPlace(options = defaultOptions) {
}
}

module.exports = initializeInPlace
export default initializeInPlace
16 changes: 10 additions & 6 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/* eslint-env node, mocha */

const { strictEqual, deepStrictEqual } = require('assert')
const Metalsmith = require('metalsmith')
const equal = require('assert-dir-equal')
const { name } = require('../package.json')
const { resolve } = require('path')
const plugin = require('../lib')
import { strictEqual, deepStrictEqual } from 'node:assert'
import { resolve, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
import { readFileSync } from 'node:fs'
import Metalsmith from 'metalsmith'
import equal from 'assert-dir-equal'
import plugin from '../src/index.js'

const __dirname = dirname(fileURLToPath(import.meta.url))
const { name } = JSON.parse(readFileSync(resolve(__dirname, '../package.json'), 'utf-8'))

function fixture(p) {
return resolve(__dirname, 'fixtures', p)
Expand Down

0 comments on commit cc84b5b

Please sign in to comment.