Skip to content

Commit

Permalink
v1.0.1 - url polyfill, better dirname/filename ponyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Aug 17, 2020
1 parent b10e8e2 commit 6f8d7ed
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
7 changes: 7 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# History

## v1.0.1 2020 August 18

- Add support for the deno `std/node/url` polyfill
- Refresh the deno cache when attempting to run our conversions
- Use Bevry's `__dirname` and `__filename` ponyfill as the community one disappeared
- Do not use the `__dirname` and `__filename` ponyfill if they are manually set

## v1.0.0 2020 August 17

- Bumped to v1 to show that is already stable and production ready, and has been used for [33 packages already](https://www.npmjs.com/search?q=keywords:deno-entry).
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "make-deno-edition",
"version": "1.0.0",
"version": "1.0.1",
"description": "Automatically makes package.json projects (such as npm packages and node.js modules) compatible with Deno.",
"homepage": "https://github.com/bevry/make-deno-edition",
"license": "MIT",
Expand Down
21 changes: 9 additions & 12 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const builtins: { [key: string]: boolean | string } = {
timers: true,
tls: false,
tty: false,
url: false,
url: true,
util: true,
v8: false,
vm: false,
Expand Down Expand Up @@ -352,17 +352,14 @@ export function convert(path: string, details: Details): File {
offset += replacement.length - i.sourceStatement.length
}

// __filename and __dirname polyfills
const f = result.includes('__filename')
const d = result.includes('__dirname')
if (f || d) {
// import url from 'url'
// __filename = url.fileURLToPath(import.meta.url)
// import { dirname } from 'path'
// const __dirname = dirname(__filename)
// __filename and __dirname ponyfill
if (
/__(file|test)name/.test(result) &&
/__(file|test)name\s?=/.test(result) === false
) {
result =
`import { __ as __fdPolyfill } from 'https://deno.land/x/dirname/mod.ts';\n` +
`const { __filename, __dirname } = __fdPolyfill(import.meta);\n` +
`import filedirname from 'https://unpkg.com/filedirname@^1.0.0/edition-deno/index.ts';\n` +
`const { __filename, __dirname } = filedirname(import.meta.url);\n` +
result
}

Expand Down Expand Up @@ -574,7 +571,7 @@ export async function make({
// attempt to run the successful files
if (run) {
for (const file of denoFiles) {
const args = ['run', ...permArgs, file.denoPath]
const args = ['run', ...permArgs, '--reload', file.denoPath]
try {
await spawn('deno', args)
} catch (err) {
Expand Down

0 comments on commit 6f8d7ed

Please sign in to comment.