-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix import proxies (JSON, CSS, etc) from npm packages (#1834)
* fix import proxies from npm packages * add test
- Loading branch information
1 parent
fcd9531
commit b16264d
Showing
9 changed files
with
80 additions
and
4 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
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,39 @@ | ||
const path = require('path'); | ||
const {setupBuildTest, readFiles} = require('../../test-utils'); | ||
|
||
const STRIP_WHITESPACE = /((\s+$)|((\\r\\n)|(\\n)))/gm; | ||
const cwd = path.join(__dirname, 'build'); | ||
let files = {}; | ||
|
||
describe('import-json', () => { | ||
beforeAll(() => { | ||
setupBuildTest(__dirname); | ||
files = readFiles( | ||
[ | ||
'_dist_/index.js', | ||
'_dist_/file.json.proxy.js', | ||
'web_modules/json-test-pkg/file.json.proxy.js', | ||
], | ||
{ | ||
cwd, | ||
}, | ||
); | ||
}); | ||
|
||
it('imports in source file are transformed correctly', () => { | ||
expect(files['/_dist_/index.js'].replace(STRIP_WHITESPACE, '')).toEqual(`import testJsonData from './file.json.proxy.js'; | ||
import testJsonPkgData from '../web_modules/json-test-pkg/file.json.proxy.js'; | ||
console.log('loaded:', testJsonData, testJsonPkgData);`); | ||
}); | ||
|
||
it('local json file is built as expected', () => { | ||
expect(files['/_dist_/file.json.proxy.js'].replace(STRIP_WHITESPACE, '')).toEqual(`let json = {"test":true}; | ||
export default json;`); | ||
}); | ||
|
||
it('npm package json file is imported as expected', () => { | ||
expect(files['/web_modules/json-test-pkg/file.json.proxy.js'].replace(STRIP_WHITESPACE, '')) | ||
.toEqual(`let json = {"test-json-pkg":true}; | ||
export default 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,16 @@ | ||
{ | ||
"private": true, | ||
"version": "1.0.1", | ||
"name": "@snowpack/test-import-json", | ||
"description": "A test to make sure that JSON imports are working properly", | ||
"scripts": { | ||
"start": "snowpack dev", | ||
"testbuild": "snowpack build" | ||
}, | ||
"dependencies": { | ||
"json-test-pkg": "file:./packages/json-test-pkg" | ||
}, | ||
"devDependencies": { | ||
"snowpack": "^2.14.3" | ||
} | ||
} |
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 @@ | ||
{"test-json-pkg": true} |
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 @@ | ||
{ | ||
"name": "test-json-pkg", | ||
"version": "0.1.0" | ||
} |
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,5 @@ | ||
{ | ||
"mount": { | ||
"./src": "/_dist_" | ||
} | ||
} |
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 @@ | ||
{"test": true} |
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 @@ | ||
import testJsonData from './file.json'; | ||
import testJsonPkgData from 'json-test-pkg/file.json'; | ||
console.log('loaded:', testJsonData, testJsonPkgData); |
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
b16264d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: