-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
.cjs
extension and stub hook (#75)
- Loading branch information
1 parent
b9cbbf1
commit 7989161
Showing
9 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require.extensions['.cjs'] = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import assert from 'assert'; | ||
import path from 'path'; | ||
import url from 'url'; | ||
|
||
import rechoir from 'rechoir'; | ||
import { extensions } from '../../../../index.js'; | ||
|
||
var fixture = path.resolve('test.cjs'); | ||
|
||
rechoir.prepare(extensions, fixture); | ||
|
||
const { default: result } = await import(url.pathToFileURL(fixture).href); | ||
|
||
const expected = { | ||
data: { | ||
trueKey: true, | ||
falseKey: false, | ||
subKey: { | ||
subProp: 1, | ||
}, | ||
}, | ||
}; | ||
|
||
assert.deepEqual(result, expected); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
data: { | ||
trueKey: true, | ||
falseKey: false, | ||
subKey: { | ||
subProp: 1, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "commonjs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
var assert = require('assert'); | ||
var path = require('path'); | ||
|
||
var rechoir = require('rechoir'); | ||
var { extensions } = require('../../../../index.js'); | ||
|
||
var fixture = path.resolve('test.cjs'); | ||
|
||
rechoir.prepare(extensions, fixture); | ||
|
||
const result = require(fixture); | ||
|
||
const expected = { | ||
data: { | ||
trueKey: true, | ||
falseKey: false, | ||
subKey: { | ||
subProp: 1, | ||
}, | ||
}, | ||
}; | ||
|
||
assert.deepEqual(result, expected); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
data: { | ||
trueKey: true, | ||
falseKey: false, | ||
subKey: { | ||
subProp: 1, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters