Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.

Commit 4a6da19

Browse files
authoredDec 10, 2018
feat: schema validation (#58)
1 parent 23a979e commit 4a6da19

25 files changed

+12636
-12898
lines changed
 

‎.circleci/config.yml

+62-78
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11
unit_tests: &unit_tests
22
steps:
33
- checkout
4-
- setup_remote_docker
54
- restore_cache:
65
key: dependency-cache-{{ checksum "package-lock.json" }}
76
- run:
8-
name: NPM Rebuild
9-
command: npm install
7+
name: Install Latest NPM.
8+
# npm@3 is buggy
9+
command: if [[ $(npm -v | cut -c -1) > 3 ]] ; then npm i -g npm@latest; else echo "Skip npm updating"; fi
1010
- run:
11-
name: Run unit tests.
11+
name: NPM Install.
12+
command: npm ci || npm i
13+
- run:
14+
name: Run Test.
1215
command: npm run ci:test
13-
# canary_tests: &canary_tests
14-
# steps:
15-
# - checkout
16-
# - setup_remote_docker
17-
# - restore_cache:
18-
# key: dependency-cache-{{ checksum "package-lock.json" }}
19-
# - run:
20-
# name: NPM Rebuild
21-
# command: npm install
22-
# - run:
23-
# name: Install Webpack Canary
24-
# command: npm i --no-save webpack@next
25-
# - run:
26-
# name: Run unit tests.
27-
# command: npm run ci:test
16+
canary_tests: &canary_tests
17+
steps:
18+
- checkout
19+
- restore_cache:
20+
key: dependency-cache-{{ checksum "package-lock.json" }}
21+
- run:
22+
name: Install Latest NPM.
23+
command: npm i -g npm@latest
24+
- run:
25+
name: NPM Install.
26+
command: npm ci
27+
- run:
28+
name: Install Webpack Canary.
29+
command: npm i --no-save webpack@next
30+
- run:
31+
name: Run Test.
32+
command: if [[ $(compver --name webpack --gte next --lt latest) < 1 ]] ; then printf "Next is older than Latest - Skipping Canary Suite"; else npm run ci:test; fi
2833

2934
version: 2
3035
jobs:
@@ -33,98 +38,85 @@ jobs:
3338
- image: webpackcontrib/circleci-node-base:latest
3439
steps:
3540
- checkout
36-
- setup_remote_docker
3741
- restore_cache:
3842
key: dependency-cache-{{ checksum "package-lock.json" }}
3943
- run:
40-
name: Install Dependencies
41-
command: npm install
44+
name: Install Latest NPM.
45+
command: npm i -g npm@latest
46+
- run:
47+
name: NPM Install.
48+
command: npm ci
4249
- save_cache:
4350
key: dependency-cache-{{ checksum "package-lock.json" }}
4451
paths:
4552
- ./node_modules
46-
53+
node6-latest:
54+
docker:
55+
- image: webpackcontrib/circleci-node6:latest
56+
<<: *unit_tests
4757
node8-latest:
4858
docker:
4959
- image: webpackcontrib/circleci-node8:latest
60+
<<: *unit_tests
61+
node10-latest:
62+
docker:
63+
- image: webpackcontrib/circleci-node10:latest
5064
steps:
5165
- checkout
52-
- setup_remote_docker
5366
- restore_cache:
5467
key: dependency-cache-{{ checksum "package-lock.json" }}
5568
- run:
56-
name: NPM Rebuild
57-
command: npm install
69+
name: Install Latest NPM.
70+
command: npm i -g npm@latest
71+
- run:
72+
name: NPM Install.
73+
command: npm ci
5874
- run:
59-
name: Run unit tests.
75+
name: Run Test.
6076
command: npm run ci:coverage
6177
- run:
6278
name: Submit coverage data to codecov.
6379
command: bash <(curl -s https://codecov.io/bash)
6480
when: on_success
65-
node6-latest:
81+
node10-canary:
6682
docker:
67-
- image: webpackcontrib/circleci-node6:latest
68-
<<: *unit_tests
69-
node9-latest:
70-
docker:
71-
- image: webpackcontrib/circleci-node9:latest
72-
<<: *unit_tests
73-
# node8-canary:
74-
# docker:
75-
# - image: webpackcontrib/circleci-node8:latest
76-
# <<: *canary_tests
83+
- image: webpackcontrib/circleci-node10:latest
84+
<<: *canary_tests
7785
analysis:
7886
docker:
7987
- image: webpackcontrib/circleci-node-base:latest
8088
steps:
8189
- checkout
82-
- setup_remote_docker
8390
- restore_cache:
8491
key: dependency-cache-{{ checksum "package-lock.json" }}
8592
- run:
86-
name: NPM Rebuild
87-
command: npm install
93+
name: Install Latest NPM.
94+
command: npm i -g npm@latest
95+
- run:
96+
name: NPM Install.
97+
command: npm ci
8898
- run:
8999
name: Run linting.
90100
command: npm run lint
91101
- run:
92-
name: Run NSP Security Check.
102+
name: Run NPM Audit.
93103
command: npm run security
94104
- run:
95-
name: Validate Commit Messages
105+
name: Validate Commit Messages.
96106
command: npm run ci:lint:commits
97-
publish:
98-
docker:
99-
- image: webpackcontrib/circleci-node-base:latest
100-
steps:
101-
- checkout
102-
- setup_remote_docker
103-
- restore_cache:
104-
key: dependency-cache-{{ checksum "package-lock.json" }}
105-
- run:
106-
name: NPM Rebuild
107-
command: npm install
108-
- run:
109-
name: Validate Commit Messages
110-
command: npm run release:validate
111-
- run:
112-
name: Publish to NPM
113-
command: printf "noop running conventional-github-releaser"
114107

115-
version: 2.0
116108
workflows:
117109
version: 2
118-
validate-publish:
110+
test:
119111
jobs:
120112
- dependency_cache
121-
- node6-latest:
113+
- analysis:
122114
requires:
123115
- dependency_cache
124116
filters:
125117
tags:
126118
only: /.*/
127-
- analysis:
119+
- node6-latest:
128120
requires:
129121
- dependency_cache
130122
filters:
@@ -137,25 +129,17 @@ workflows:
137129
filters:
138130
tags:
139131
only: /.*/
140-
- node9-latest:
132+
- node10-latest:
141133
requires:
142134
- analysis
143135
- node6-latest
144136
filters:
145137
tags:
146138
only: /.*/
147-
# - node8-canary:
148-
# requires:
149-
# - analysis
150-
# - node6-latest
151-
# filters:
152-
# tags:
153-
# only: /.*/
154-
- publish:
139+
- node10-canary:
155140
requires:
156-
- node8-latest
157-
- node9-latest
141+
- analysis
142+
- node6-latest
158143
filters:
159-
branches:
160-
only:
161-
- master
144+
tags:
145+
only: /.*/

‎.github/CONTRIBUTING.md

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
## Contributing in @webpack-contrib
2+
3+
We'd always love contributions to further improve the webpack / webpack-contrib ecosystem!
4+
Here are the guidelines we'd like you to follow:
5+
6+
* [Questions and Problems](#question)
7+
* [Issues and Bugs](#issue)
8+
* [Feature Requests](#feature)
9+
* [Pull Request Submission Guidelines](#submit-pr)
10+
* [Commit Message Conventions](#commit)
11+
12+
### <a name="question"></a> Got a Question or Problem?
13+
14+
Please submit support requests and questions to StackOverflow using the tag [[webpack]](http://stackoverflow.com/tags/webpack).
15+
StackOverflow is better suited for this kind of support though you may also inquire in [Webpack Gitter](https://gitter.im/webpack/webpack).
16+
The issue tracker is for bug reports and feature discussions.
17+
18+
### <a name="issue"></a> Found an Issue or Bug?
19+
20+
Before you submit an issue, please search the issue tracker, maybe an issue for your problem already exists and the discussion might inform you of workarounds readily available.
21+
22+
We want to fix all the issues as soon as possible, but before fixing a bug we need to reproduce and confirm it. In order to reproduce bugs, we ask that you to provide a minimal reproduction scenario (github repo or failing test case). Having a live, reproducible scenario gives us a wealth of important information without going back & forth to you with additional questions like:
23+
24+
- version of Webpack used
25+
- version of the loader / plugin you are creating a bug report for
26+
- the use-case that fails
27+
28+
A minimal reproduce scenario allows us to quickly confirm a bug (or point out config problems) as well as confirm that we are fixing the right problem.
29+
30+
We will be insisting on a minimal reproduce scenario in order to save maintainers time and ultimately be able to fix more bugs. We understand that sometimes it might be hard to extract essentials bits of code from a larger code-base but we really need to isolate the problem before we can fix it.
31+
32+
Unfortunately, we are not able to investigate / fix bugs without a minimal reproduction, so if we don't hear back from you we are going to close an issue that doesn't have enough info to be reproduced.
33+
34+
### <a name="feature"></a> Feature Requests?
35+
36+
You can *request* a new feature by creating an issue on Github.
37+
38+
If you would like to *implement* a new feature, please submit an issue with a proposal for your work `first`, to be sure that particular makes sense for the project.
39+
40+
### <a name="submit-pr"></a> Pull Request Submission Guidelines
41+
42+
Before you submit your Pull Request (PR) consider the following guidelines:
43+
44+
- Search Github for an open or closed PR that relates to your submission. You don't want to duplicate effort.
45+
- Commit your changes using a descriptive commit message that follows our [commit message conventions](#commit). Adherence to these conventions is necessary because release notes are automatically generated from these messages.
46+
- Fill out our `Pull Request Template`. Your pull request will not be considered if it is ignored.
47+
- Please sign the `Contributor License Agreement (CLA)` when a pull request is opened. We cannot accept your pull request without this. Make sure you sign with the primary email address associated with your local / github account.
48+
49+
### <a name="commit"></a> Webpack Contrib Commit Conventions
50+
51+
Each commit message consists of a **header**, a **body** and a **footer**. The header has a special
52+
format that includes a **type**, a **scope** and a **subject**:
53+
54+
```
55+
<type>(<scope>): <subject>
56+
<BLANK LINE>
57+
<body>
58+
<BLANK LINE>
59+
<footer>
60+
```
61+
62+
The **header** is mandatory and the **scope** of the header is optional.
63+
64+
Any line of the commit message cannot be longer 100 characters! This allows the message to be easier
65+
to read on GitHub as well as in various git tools.
66+
67+
The footer should contain a [closing reference to an issue](https://help.github.com/articles/closing-issues-via-commit-messages/) if any.
68+
69+
Examples:
70+
```
71+
docs(readme): update install instructions
72+
```
73+
```
74+
fix: refer to the `entrypoint` instead of the first `module`
75+
```
76+
77+
#### Revert
78+
If the commit reverts a previous commit, it should begin with `revert: `, followed by the header of the reverted commit.
79+
In the body it should say: `This reverts commit <hash>.`, where the hash is the SHA of the commit being reverted.
80+
81+
#### Type
82+
Must be one of the following:
83+
84+
* **build**: Changes that affect the build system or external dependencies (example scopes: babel, npm)
85+
* **chore**: Changes that fall outside of build / docs that do not effect source code (example scopes: package, defaults)
86+
* **ci**: Changes to our CI configuration files and scripts (example scopes: circleci, travis)
87+
* **docs**: Documentation only changes (example scopes: readme, changelog)
88+
* **feat**: A new feature
89+
* **fix**: A bug fix
90+
* **perf**: A code change that improves performance
91+
* **refactor**: A code change that neither fixes a bug nor adds a feature
92+
* **revert**: Used when reverting a committed change
93+
* **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons)
94+
* **test**: Addition of or updates to Jest tests
95+
96+
#### Scope
97+
The scope is subjective & depends on the `type` see above. A good example would be a change to a particular class / module.
98+
99+
#### Subject
100+
The subject contains a succinct description of the change:
101+
102+
* use the imperative, present tense: "change" not "changed" nor "changes"
103+
* don't capitalize the first letter
104+
* no dot (.) at the end
105+
106+
#### Body
107+
Just as in the **subject**, use the imperative, present tense: "change" not "changed" nor "changes".
108+
The body should include the motivation for the change and contrast this with previous behavior.
109+
110+
#### Footer
111+
The footer should contain any information about **Breaking Changes** and is also the place to
112+
reference GitHub issues that this commit **Closes**.
113+
114+
**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines. The rest of the commit message is then used for this.
115+
116+
Example
117+
118+
```
119+
BREAKING CHANGE: Updates to `Chunk.mapModules`.
120+
121+
This release is not backwards compatible with `Webpack 2.x` due to breaking changes in webpack/webpack#4764
122+
Migration: see webpack/webpack#5225
123+
124+
```

‎.github/ISSUE_TEMPLATE.md

+9-58
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,16 @@
11
<!--
2-
Issues are so 🔥
3-
4-
If you remove or skip this template, you'll make the 🐼 sad and the mighty god
5-
of Github will appear and pile-drive the close button from a great height
6-
while making animal noises.
7-
82
👉🏽 Need support, advice, or help? Don't open an issue!
93
Head to StackOverflow or https://gitter.im/webpack/webpack.
10-
-->
11-
12-
* Operating System:
13-
* Node Version:
14-
* NPM Version:
15-
* webpack Version:
16-
* webpack-serve Version:
17-
18-
<!-- Please place an x (no spaces!) in all [ ] that apply -->
19-
20-
This issue is for a:
21-
22-
- [ ] **bug**
23-
- [ ] **feature** request
24-
- [ ] **modification** request
25-
26-
### Code
27-
28-
##### CLI Command
29-
30-
```bash
31-
# paste the CLI command you're using. if this isn't applicable, it's safe to remove.
32-
$ {the command}
33-
```
344
35-
##### webpack.config.js
5+
Hey there!
366
37-
```js
38-
// If your bitchin' code blocks are over 20 lines, please paste a link to a gist
39-
// (https://gist.github.com).
40-
```
7+
You arrived at this template because you felt none of the other options
8+
matched the kind of issue you'd like to report. Please use this opportunity to
9+
tell us about your particular type of issue so we can try to accomodate
10+
similar issues in the future.
4111
42-
```js
43-
// additional code, HEY YO remove this block if you don't need it
44-
```
45-
46-
### Expected Behavior
47-
48-
<!-- Remove this section if not reporting a bug or modification request. -->
49-
50-
### Actual Behavior
51-
52-
<!-- Remove this section if not reporting a bug or modification request. -->
53-
54-
### How Do We Reproduce?
55-
56-
<!--
57-
Remove this section if not reporting a bug.
58-
59-
If your webpack config is over 50 lines long, please provide a URL to a repo
60-
for your beefy 🍖 app that we can use to reproduce.
12+
PLEASE do note, if you're using this to report an issue already covered by the
13+
existing template types, your issue may be closed as invalid. Our issue
14+
templates contain fields that help us help you, and without that important
15+
info, we might as well be ice-skating uphill, carrying a wooly mammoth.
6116
-->
62-
63-
### New Feature Use Case
64-
65-
<!-- Remove this section if not requesting a feature -->

‎.github/ISSUE_TEMPLATE/BUG.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
name: 🐛 Bug Report
3+
about: Something went awry and you'd like to tell us about it.
4+
5+
---
6+
7+
<!--
8+
Issues are so 🔥
9+
10+
If you remove or skip this template, you'll make the 🐼 sad and the mighty god
11+
of Github will appear and pile-drive the close button from a great height
12+
while making animal noises.
13+
14+
👉🏽 Need support, advice, or help? Don't open an issue!
15+
Head to StackOverflow or https://gitter.im/webpack/webpack.
16+
-->
17+
18+
* Operating System:
19+
* Node Version:
20+
* NPM Version:
21+
* webpack Version:
22+
* raw-loader Version:
23+
24+
### Expected Behavior
25+
26+
<!-- Remove this section if not reporting a bug or modification request. -->
27+
28+
### Actual Behavior
29+
30+
<!-- Remove this section if not reporting a bug or modification request. -->
31+
32+
### Code
33+
34+
```js
35+
// webpack.config.js
36+
// If your bitchin' code blocks are over 20 lines, please paste a link to a gist
37+
// (https://gist.github.com).
38+
```
39+
40+
```js
41+
// additional code, HEY YO remove this block if you don't need it
42+
```
43+
44+
### How Do We Reproduce?
45+
46+
<!--
47+
Remove this section if not reporting a bug.
48+
49+
If your webpack config is over 50 lines long, please provide a URL to a repo
50+
for your beefy 🍖 app that we can use to reproduce.
51+
-->

‎.github/ISSUE_TEMPLATE/DOCS.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
name: 📚 Documentation
3+
about: Are the docs lacking or missing something? Do they need some new 🔥 hotness? Tell us here.
4+
5+
---
6+
7+
<!--
8+
Issues are so 🔥
9+
10+
If you remove or skip this template, you'll make the 🐼 sad and the mighty god
11+
of Github will appear and pile-drive the close button from a great height
12+
while making animal noises.
13+
14+
👉🏽 Need support, advice, or help? Don't open an issue!
15+
Head to StackOverflow or https://gitter.im/webpack/webpack.
16+
-->
17+
18+
Documentation Is:
19+
20+
<!-- Please place an x (no spaces!) in all [ ] that apply -->
21+
22+
- [ ] Missing
23+
- [ ] Needed
24+
- [ ] Confusing
25+
- [ ] Not Sure?
26+
27+
### Please Explain in Detail...
28+
29+
30+
### Your Proposal for Changes

‎.github/ISSUE_TEMPLATE/FEATURE.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: ✨ Feature Request
3+
about: Suggest an idea for this project
4+
5+
---
6+
7+
<!--
8+
Issues are so 🔥
9+
10+
If you remove or skip this template, you'll make the 🐼 sad and the mighty god
11+
of Github will appear and pile-drive the close button from a great height
12+
while making animal noises.
13+
14+
👉🏽 Need support, advice, or help? Don't open an issue!
15+
Head to StackOverflow or https://gitter.im/webpack/webpack.
16+
-->
17+
18+
* Operating System:
19+
* Node Version:
20+
* NPM Version:
21+
* webpack Version:
22+
* raw-loader Version:
23+
24+
### Feature Proposal
25+
26+
27+
28+
### Feature Use Case
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
name: 🔧 Modification Request
3+
about: Would you like something work differently? Have an alternative approach? This is the template for you.
4+
5+
---
6+
7+
<!--
8+
Issues are so 🔥
9+
10+
If you remove or skip this template, you'll make the 🐼 sad and the mighty god
11+
of Github will appear and pile-drive the close button from a great height
12+
while making animal noises.
13+
14+
👉🏽 Need support, advice, or help? Don't open an issue!
15+
Head to StackOverflow or https://gitter.im/webpack/webpack.
16+
-->
17+
18+
* Operating System:
19+
* Node Version:
20+
* NPM Version:
21+
* webpack Version:
22+
* raw-loader Version:
23+
24+
25+
### Expected Behavior / Situation
26+
27+
28+
29+
### Actual Behavior / Situation
30+
31+
32+
33+
### Modification Proposal

‎.github/ISSUE_TEMPLATE/SUPPORT.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
name: 🆘 Support, Help, and Advice
3+
about: 👉🏽 Need support, help, or advice? Don't open an issue! Head to StackOverflow or https://gitter.im/webpack/webpack.
4+
5+
---
6+
7+
Hey there! If you need support, help, or advice then this is not the place to ask.
8+
Please visit [StackOverflow](https://stackoverflow.com/questions/tagged/webpack)
9+
or [the Webpack Gitter](https://gitter.im/webpack/webpack) instead.

‎.github/PULL_REQUEST_TEMPLATE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ This PR contains a:
3232
migration path for existing applications.
3333
-->
3434

35-
### Additional Info
35+
### Additional Info

‎README.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
[![node][node]][node-url]
99
[![deps][deps]][deps-url]
1010
[![tests][tests]][tests-url]
11+
[![coverage][cover]][cover-url]
1112
[![chat][chat]][chat-url]
13+
[![size][size]][size-url]
1214

1315
# raw-loader
1416

@@ -60,18 +62,15 @@ And run `webpack` via your preferred method.
6062

6163
[npm]: https://img.shields.io/npm/v/raw-loader.svg
6264
[npm-url]: https://npmjs.com/package/raw-loader
63-
6465
[node]: https://img.shields.io/node/v/raw-loader.svg
6566
[node-url]: https://nodejs.org
66-
6767
[deps]: https://david-dm.org/webpack-contrib/raw-loader.svg
6868
[deps-url]: https://david-dm.org/webpack-contrib/raw-loader
69-
7069
[tests]: https://img.shields.io/circleci/project/github/webpack-contrib/raw-loader.svg
7170
[tests-url]: https://circleci.com/gh/webpack-contrib/raw-loader
72-
7371
[cover]: https://codecov.io/gh/webpack-contrib/raw-loader/branch/master/graph/badge.svg
7472
[cover-url]: https://codecov.io/gh/webpack-contrib/raw-loader
75-
7673
[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
77-
[chat-url]: https://gitter.im/webpack/webpack
74+
[chat-url]: https://gitter.im/webpack/webpack
75+
[size]: https://packagephobia.now.sh/badge?p=raw-loader
76+
[size-url]: https://packagephobia.now.sh/result?p=raw-loader

‎appveyor.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
branches:
2+
only:
3+
- master
4+
- next
5+
init:
6+
- git config --global core.autocrlf input
7+
cache:
8+
- node_modules
9+
- '%APPDATA%\npm-cache'
10+
environment:
11+
matrix:
12+
- nodejs_version: '11'
13+
webpack_version: latest
14+
job_part: test
15+
- nodejs_version: '10'
16+
webpack_version: latest
17+
job_part: test
18+
- nodejs_version: '8'
19+
webpack_version: latest
20+
job_part: test
21+
- nodejs_version: '6'
22+
webpack_version: latest
23+
job_part: test
24+
- nodejs_version: '6'
25+
webpack_version: latest
26+
job_part: next
27+
build: 'off'
28+
matrix:
29+
fast_finish: true
30+
install:
31+
- ps: Install-Product node $env:nodejs_version x64
32+
- npm i -g npm@latest
33+
- npm ci
34+
- npm i -g @webpack-contrib/tag-versions
35+
before_test:
36+
- cmd: npm install webpack@%webpack_version%
37+
test_script:
38+
- node --version
39+
- node --version
40+
- npm --version
41+
- cmd: FOR /F %%I in ('compver --name webpack --gte %webpack_version% --lt latest') do SET COMPARED_VERSION_RESULT=%%I
42+
- cmd: IF %COMPARED_VERSION_RESULT% NEQ -1 (npm run ci:test) ELSE (ECHO "Next is older than Latest - Skipping Canary Suite")

‎codecov.yml

-10
This file was deleted.

‎commitlint.config.js

-32
This file was deleted.

‎index.js

+10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5+
6+
const { getOptions } = require('loader-utils');
7+
const validateOptions = require('schema-utils');
8+
9+
const schema = require('./options');
10+
511
module.exports = function rawLoader(source) {
12+
const options = getOptions(this) || {};
13+
14+
validateOptions(schema, options, 'Raw Loader');
15+
616
const json = JSON.stringify(source)
717
.replace(/\u2028/g, '\\u2028')
818
.replace(/\u2029/g, '\\u2029');

‎options.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"additionalProperties": false,
3+
"properties": {},
4+
"type": "object"
5+
}

‎package-lock.json

+11,993-12,637
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+90-72
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,92 @@
11
{
2-
"name": "raw-loader",
3-
"version": "0.5.1",
4-
"description": "A loader for webpack that allows importing files as a String",
5-
"license": "MIT",
6-
"repository": "webpack-contrib/raw-loader",
7-
"author": "Tobias Koppers @sokra",
8-
"homepage": "https://github.com/webpack-contrib/raw-loader",
9-
"bugs": "https://github.com/webpack-contrib/raw-loader/issues",
10-
"main": "index.js",
11-
"engines": {
12-
"node": ">= 6.9.0"
13-
},
14-
"scripts": {
15-
"commitlint": "commitlint",
16-
"commitmsg": "commitlint -e $GIT_PARAMS",
17-
"lint": "eslint --cache src test",
18-
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
19-
"lint-staged": "lint-staged",
20-
"release": "standard-version",
21-
"release:ci": "conventional-github-releaser -p angular",
22-
"release:validate": "commitlint --from=$(git describe --tags --abbrev=0) --to=$(git rev-parse HEAD)",
23-
"security": "nsp check",
24-
"test": "jest",
25-
"test:watch": "jest --watch",
26-
"test:coverage": "jest --collectCoverageFrom='src/**/*.js' --coverage",
27-
"ci:lint": "npm run lint && npm run security",
28-
"ci:test": "npm run test -- --runInBand",
29-
"ci:coverage": "npm run test:coverage -- --runInBand",
30-
"defaults": "webpack-defaults"
31-
},
32-
"files": [
33-
"index.js"
34-
],
35-
"peerDependencies": {
36-
"webpack": "^4.3.0"
37-
},
38-
"dependencies": {
39-
},
40-
"devDependencies": {
41-
"@commitlint/cli": "^6.1.3",
42-
"@commitlint/config-angular": "^6.1.3",
43-
"@webpack-contrib/eslint-config-webpack": "^2.0.2",
44-
"babel-cli": "^6.26.0",
45-
"babel-jest": "^22.4.3",
46-
"babel-plugin-transform-object-rest-spread": "^6.26.0",
47-
"babel-polyfill": "^6.26.0",
48-
"babel-preset-env": "^1.6.1",
49-
"conventional-github-releaser": "^2.0.2",
50-
"cross-env": "^5.1.4",
51-
"del": "^3.0.0",
52-
"del-cli": "^1.1.0",
53-
"eslint": "^4.19.1",
54-
"eslint-plugin-import": "^2.9.0",
55-
"eslint-plugin-prettier": "^2.6.0",
56-
"husky": "^0.14.3",
57-
"jest": "^22.4.3",
58-
"lint-staged": "^7.0.0",
59-
"memory-fs": "^0.4.1",
60-
"nsp": "^3.2.1",
61-
"pre-commit": "^1.2.2",
62-
"prettier": "^1.11.1",
63-
"standard-version": "^4.3.0",
64-
"webpack": "^4.3.0",
65-
"webpack-defaults": "^2.1.1"
66-
},
67-
"pre-commit": "lint-staged",
68-
"lint-staged": {
69-
"*.js": [
70-
"eslint --fix",
71-
"git add"
72-
]
73-
}
2+
"name": "raw-loader",
3+
"version": "0.5.1",
4+
"description": "A loader for webpack that allows importing files as a String",
5+
"license": "MIT",
6+
"repository": "webpack-contrib/raw-loader",
7+
"author": "Tobias Koppers @sokra",
8+
"homepage": "https://github.com/webpack-contrib/raw-loader",
9+
"bugs": "https://github.com/webpack-contrib/raw-loader/issues",
10+
"main": "index.js",
11+
"engines": {
12+
"node": ">= 6.9.0"
13+
},
14+
"scripts": {
15+
"lint": "eslint --cache 'index.js' test",
16+
"release": "standard-version",
17+
"security": "npm audit",
18+
"test": "jest",
19+
"test:watch": "jest --watch",
20+
"test:coverage": "jest --collectCoverageFrom='index.js' --coverage",
21+
"ci:lint": "npm run lint && npm run security",
22+
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
23+
"ci:test": "npm run test -- --runInBand",
24+
"ci:coverage": "npm run test:coverage -- --runInBand",
25+
"defaults": "webpack-defaults"
26+
},
27+
"files": [
28+
"index.js",
29+
"options.json"
30+
],
31+
"peerDependencies": {
32+
"webpack": "^4.3.0"
33+
},
34+
"dependencies": {
35+
"loader-utils": "^1.1.0",
36+
"schema-utils": "^1.0.0"
37+
},
38+
"devDependencies": {
39+
"@babel/cli": "^7.1.5",
40+
"@babel/core": "^7.1.6",
41+
"@babel/polyfill": "^7.0.0",
42+
"@babel/preset-env": "^7.1.6",
43+
"@commitlint/cli": "^7.1.6",
44+
"@commitlint/config-conventional": "^7.1.2",
45+
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
46+
"babel-core": "^7.0.0-bridge.0",
47+
"babel-jest": "^23.6.0",
48+
"cross-env": "^5.2.0",
49+
"del": "^3.0.0",
50+
"del-cli": "^1.1.0",
51+
"eslint": "^5.10.0",
52+
"eslint-plugin-import": "^2.14.0",
53+
"eslint-plugin-prettier": "^3.0.0",
54+
"husky": "^1.2.0",
55+
"jest": "^23.6.0",
56+
"lint-staged": "^8.1.0",
57+
"memory-fs": "^0.4.1",
58+
"prettier": "^1.11.1",
59+
"standard-version": "^4.3.0",
60+
"webpack": "^4.3.0",
61+
"webpack-defaults": "^2.1.1"
62+
},
63+
"babel": {
64+
"presets": [
65+
[
66+
"@babel/preset-env",
67+
{
68+
"targets": {
69+
"node": "6.9.0"
70+
},
71+
"useBuiltIns": "usage"
72+
}
73+
]
74+
]
75+
},
76+
"husky": {
77+
"hooks": {
78+
"pre-commit": "lint-staged"
79+
}
80+
},
81+
"lint-staged": {
82+
"*.js": [
83+
"eslint --fix",
84+
"git add"
85+
]
86+
},
87+
"commitlint": {
88+
"extends": [
89+
"@commitlint/config-conventional"
90+
]
91+
}
7492
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`validation 1`] = `
4+
"Raw Loader Invalid Options
5+
6+
options should NOT have additional properties
7+
"
8+
`;
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`loader should works: errors 1`] = `Array []`;
4+
5+
exports[`loader should works: file 1`] = `"module.exports = \\"Где розы — там и тернии —\\\\nТаков закон судьбы.\\\\n\\\\nНиколай Алексеевич Некрасов\\\\n\\\\nWhere the roses are - there are thorns -\\\\nThat is the law of fate.\\\\n\\\\nNikolay Alekseevich Nekrasov\\\\n\\""`;
6+
7+
exports[`loader should works: separator 1`] = `"module.exports = \\"Word\\\\u2028Word\\\\u2029Word\\\\n\\""`;
8+
9+
exports[`loader should works: warnings 1`] = `Array []`;

‎test/errors.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import loader from '../index';
2+
3+
it('validation', () => {
4+
const validate = (options) =>
5+
loader.call(
6+
Object.assign(
7+
{},
8+
{
9+
query: options,
10+
}
11+
),
12+
'Text'
13+
);
14+
15+
expect(() => validate({})).not.toThrow();
16+
expect(() => validate(true)).not.toThrow();
17+
expect(() => validate({ unknown: true })).toThrowErrorMatchingSnapshot();
18+
});

‎test/fixtures/basic.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import txt from './file.txt';
2+
import separator from './separator.txt';
3+
4+
export { txt, separator };

‎test/fixtures/file.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Где розы — там и тернии —
2+
Таков закон судьбы.
3+
4+
Николай Алексеевич Некрасов
5+
6+
Where the roses are - there are thorns -
7+
That is the law of fate.
8+
9+
Nikolay Alekseevich Nekrasov

‎test/fixtures/separator.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Word
Word
Word

‎test/helpers.js

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import path from 'path';
2+
3+
import webpack from 'webpack';
4+
import MemoryFS from 'memory-fs';
5+
import del from 'del';
6+
7+
const moduleConfig = (config) => {
8+
return {
9+
rules: config.rules
10+
? config.rules
11+
: [
12+
{
13+
test: (config.loader && config.loader.test) || /\.txt/,
14+
use: [
15+
{
16+
loader: path.resolve(__dirname, '../index.js'),
17+
options: (config.loader && config.loader.options) || {},
18+
},
19+
],
20+
},
21+
],
22+
};
23+
};
24+
const pluginsConfig = (config) => [].concat(config.plugins || []);
25+
const outputConfig = (config) => {
26+
return {
27+
path: path.resolve(
28+
__dirname,
29+
`../outputs/${config.output ? config.output : ''}`
30+
),
31+
filename: '[name].bundle.js',
32+
};
33+
};
34+
35+
function compile(fixture, config = {}, options = {}) {
36+
// webpack Config
37+
// eslint-disable-next-line no-param-reassign
38+
config = {
39+
mode: 'development',
40+
devtool: config.devtool || 'sourcemap',
41+
context: path.resolve(__dirname, 'fixtures'),
42+
entry: path.resolve(__dirname, 'fixtures', fixture),
43+
output: outputConfig(config),
44+
module: moduleConfig(config),
45+
plugins: pluginsConfig(config),
46+
optimization: {
47+
runtimeChunk: true,
48+
},
49+
resolve: {
50+
alias: {
51+
aliasesImg: path.resolve(__dirname, 'fixtures/url'),
52+
aliasesImport: path.resolve(__dirname, 'fixtures/import'),
53+
aliasesComposes: path.resolve(__dirname, 'fixtures/modules'),
54+
},
55+
},
56+
};
57+
58+
// Compiler Options
59+
// eslint-disable-next-line no-param-reassign
60+
options = Object.assign({ output: false }, options);
61+
62+
if (options.output) {
63+
del.sync(config.output.path);
64+
}
65+
66+
const compiler = webpack(config);
67+
68+
if (!options.output) {
69+
compiler.outputFileSystem = new MemoryFS();
70+
}
71+
72+
return new Promise((resolve, reject) =>
73+
compiler.run((error, stats) => {
74+
if (error) {
75+
return reject(error);
76+
}
77+
return resolve(stats);
78+
})
79+
);
80+
}
81+
82+
module.exports = {
83+
webpack: compile,
84+
};

‎test/loader.test.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
const loader = require('../');
1+
import { webpack } from './helpers';
22

3-
describe('Loader', () => {
4-
test('Defaults', () => {
5-
expect(loader);
3+
describe('loader', () => {
4+
it('should works', async () => {
5+
const stats = await webpack('basic.js');
6+
const { modules } = stats.toJson();
7+
const [, file, separator] = modules;
8+
9+
expect(file.source).toMatchSnapshot('file');
10+
expect(separator.source).toMatchSnapshot('separator');
11+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
12+
expect(stats.compilation.errors).toMatchSnapshot('errors');
613
});
714
});

0 commit comments

Comments
 (0)
This repository has been archived.