-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
63 additions
and
0 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,10 @@ | ||
const fs = require('fs'); | ||
const crypto = require('crypto'); | ||
|
||
const util = require('./util'); | ||
|
||
(async () => { | ||
let contents = await util.open('package.json'); | ||
|
||
console.log(contents); | ||
})(); |
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 @@ | ||
{ | ||
"description": "i'm a commonjs app" | ||
} |
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,11 @@ | ||
const fs = require('fs/promises'); | ||
|
||
module.exports = { | ||
|
||
async open(file) { | ||
let content = await fs.readFile(file); | ||
|
||
return content.toString(); | ||
} | ||
|
||
}; |
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,8 @@ | ||
import fs from 'fs'; | ||
import crypto from 'crypto'; | ||
|
||
import util from './util.js'; | ||
|
||
let contents = await util.open('package.json'); | ||
|
||
console.log(contents); |
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,4 @@ | ||
{ | ||
"type": "module", | ||
"description": "i'm an esm app" | ||
} |
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,11 @@ | ||
import fs from 'fs/promises'; | ||
|
||
export default { | ||
|
||
async open(file) { | ||
let content = await fs.readFile(file); | ||
|
||
return content.toString(); | ||
} | ||
|
||
}; |
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,16 @@ | ||
prereqs: | ||
- upgrade to at least node 12, 16 preferred | ||
|
||
how to go esm: | ||
- add "type": "module" to package.json | ||
- change out calls to require() with import | ||
- change out module.exports to export default | ||
- remove top level self-executing functions | ||
- remove 'use strict'; from everywhere | ||
|
||
caveats: | ||
- the above steps get you 90% the way | ||
|
||
import * as url from 'url'; | ||
const __filename = url.fileURLToPath(import.meta.url); | ||
const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); |