Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@parcel/transformer-js): Rewrite
__dirname
/__filename
to be …
…relative to `asset.filePath` (#7727) Co-authored-by: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com>
- Loading branch information
Showing
13 changed files
with
466 additions
and
3 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
File renamed without changes.
24 changes: 24 additions & 0 deletions
24
packages/core/integration-tests/test/integration/env-node-replacements/index.js
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 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const otherFunction = require('./other/function') | ||
const subFunction = require('./sub/index') | ||
|
||
module.exports = function () { | ||
const data = fs.readFileSync(path.join(__dirname, 'data', 'test.txt'), 'utf8') | ||
const firstDirnameTest = path.join(__dirname, 'data') | ||
const secondDirnameTest = path.join(__dirname, 'other-data') | ||
const firstFilenameTest = __filename | ||
const secondFilenameTest = `${__filename}?query-string=test` | ||
const other = otherFunction() | ||
const sub = subFunction() | ||
|
||
return { | ||
data, | ||
firstDirnameTest, | ||
secondDirnameTest, | ||
firstFilenameTest, | ||
secondFilenameTest, | ||
other, | ||
sub, | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/core/integration-tests/test/integration/env-node-replacements/other/function.js
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,6 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
module.exports = function () { | ||
return fs.readFileSync(path.join(__dirname, '..', 'data', 'test.txt'), 'utf8') | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/core/integration-tests/test/integration/env-node-replacements/package.json
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,6 @@ | ||
{ | ||
"name": "env-node-replacements", | ||
"engines": { | ||
"node": ">=14" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/core/integration-tests/test/integration/env-node-replacements/sub/index.js
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,6 @@ | ||
module.exports = function () { | ||
return { | ||
dirname: __dirname, | ||
filename: __filename | ||
} | ||
} |
Empty file.
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
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
Oops, something went wrong.