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

Commit

Permalink
chore: integrate babel (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Feb 12, 2019
1 parent 6519eb2 commit 7fa759c
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 29 deletions.
20 changes: 0 additions & 20 deletions index.js

This file was deleted.

13 changes: 8 additions & 5 deletions package.json
Expand Up @@ -7,29 +7,32 @@
"author": "Tobias Koppers @sokra",
"homepage": "https://github.com/webpack-contrib/raw-loader",
"bugs": "https://github.com/webpack-contrib/raw-loader/issues",
"main": "index.js",
"main": "dist/cjs.js",
"engines": {
"node": ">= 6.9.0"
},
"scripts": {
"start": "npm run build -- -w",
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js' --copy-files",
"clean": "del-cli dist",
"commitlint": "commitlint",
"commitmsg": "commitlint -e $GIT_PARAMS",
"lint": "eslint --cache index.js test",
"lint": "eslint --cache src test",
"prebuild": "npm run clean",
"prepublish": "npm run build",
"release": "standard-version",
"security": "npm audit",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --collectCoverageFrom='index.js' --coverage",
"test:coverage": "jest --collectCoverageFrom='src/**/*.js' --coverage",
"ci:lint": "npm run lint && npm run security",
"ci:test": "npm run test -- --runInBand",
"ci:coverage": "npm run test:coverage -- --runInBand",
"ci:lint:commits": "commitlint --from=origin/master --to=${CIRCLE_SHA1}",
"defaults": "webpack-defaults"
},
"files": [
"index.js",
"options.json"
"dist/"
],
"peerDependencies": {
"webpack": "^4.3.0"
Expand Down
3 changes: 3 additions & 0 deletions src/cjs.js
@@ -0,0 +1,3 @@
const loader = require('./index');

module.exports = loader.default;
16 changes: 16 additions & 0 deletions src/index.js
@@ -0,0 +1,16 @@
import { getOptions } from 'loader-utils';
import validateOptions from 'schema-utils';

import schema from './options.json';

export default function rawLoader(source) {
const options = getOptions(this) || {};

validateOptions(schema, options, 'Raw Loader');

const json = JSON.stringify(source)
.replace(/\u2028/g, '\\u2028')
.replace(/\u2029/g, '\\u2029');

return `module.exports = ${json}`;
}
File renamed without changes.
2 changes: 2 additions & 0 deletions test/__snapshots__/loader.test.js.snap
Expand Up @@ -4,6 +4,8 @@ exports[`loader should works: errors 1`] = `Array []`;

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\\""`;

exports[`loader should works: inline 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\\""`;

exports[`loader should works: separator 1`] = `"module.exports = \\"Word\\\\u2028Word\\\\u2029Word\\\\n\\""`;

exports[`loader should works: warnings 1`] = `Array []`;
8 changes: 8 additions & 0 deletions test/cjs.test.js
@@ -0,0 +1,8 @@
import src from '../src';
import cjs from '../src/cjs';

describe('cjs', () => {
it('should exported', () => {
expect(cjs).toEqual(src);
});
});
5 changes: 4 additions & 1 deletion test/fixtures/basic.js
@@ -1,4 +1,7 @@
// eslint-disable-next-line import/no-webpack-loader-syntax, import/no-unresolved
import inline from '!!../../src/index.js!./file.txt';

import txt from './file.txt';
import separator from './separator.txt';

export { txt, separator };
export { txt, separator, inline };
2 changes: 1 addition & 1 deletion test/helpers.js
Expand Up @@ -13,7 +13,7 @@ const moduleConfig = (config) => {
test: (config.loader && config.loader.test) || /\.txt/,
use: [
{
loader: path.resolve(__dirname, '../index.js'),
loader: path.resolve(__dirname, '../src/index.js'),
options: (config.loader && config.loader.options) || {},
},
],
Expand Down
4 changes: 3 additions & 1 deletion test/loader.test.js
Expand Up @@ -4,10 +4,12 @@ describe('loader', () => {
it('should works', async () => {
const stats = await webpack('basic.js');
const { modules } = stats.toJson();
const [, file, separator] = modules;
const [inline, , file, separator] = modules;

expect(inline.source).toMatchSnapshot('inline');
expect(file.source).toMatchSnapshot('file');
expect(separator.source).toMatchSnapshot('separator');

expect(stats.compilation.warnings).toMatchSnapshot('warnings');
expect(stats.compilation.errors).toMatchSnapshot('errors');
});
Expand Down
2 changes: 1 addition & 1 deletion test/errors.test.js → test/validation.test.js
@@ -1,4 +1,4 @@
import loader from '../index';
import loader from '../src';

it('validation', () => {
const validate = (options) =>
Expand Down

0 comments on commit 7fa759c

Please sign in to comment.