Skip to content

Commit 2984692

Browse files
committed
migrated from yarn lockfile to npm lockfile (+ added it to git index); upgraded dependencies and node versiob; improved and reorganized some code; added automatic code formatting
1 parent a2e006c commit 2984692

File tree

14 files changed

+6738
-1390
lines changed

14 files changed

+6738
-1390
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
*.swp
55
node_modules/*
66
!node_modules/__this-loader/
7-
package-lock.json
8-
test/build/
7+
test_subj/build/

.npmignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
*.swp
55
node_modules/
66
package-lock.json
7-
yarn.lock
87
test/
8+
test_subj/

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const processChuck = require('./lib/processChunk')
1+
const loader = require('./lib/loader.js')
22

3-
module.exports = processChuck
3+
module.exports = loader
Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
const { getOptions } = require('loader-utils')
21
const { validate } = require('schema-utils')
32

4-
const loaderName = 'string-replace-loader'
5-
63
const optionsSchema = {
74
type: 'object',
85
properties: {
@@ -27,7 +24,7 @@ const optionsSchema = {
2724
]
2825
},
2926
flags: {
30-
type: 'string',
27+
type: 'string'
3128
},
3229
strict: {
3330
type: 'boolean'
@@ -43,22 +40,24 @@ const defaultOptions = {
4340
strict: false
4441
}
4542

46-
function getOptionsArray (config) {
47-
const rawOptions = getOptions(config)
48-
const rawOptionsArray = (
43+
function getOptionsArr (loaderName, context) {
44+
const rawOptions = context.getOptions()
45+
const rawOptionsArr = (
4946
typeof rawOptions.multiple !== 'undefined'
5047
? rawOptions.multiple
5148
: [rawOptions]
5249
)
53-
const optionsArray = []
50+
const optionsArr = []
51+
52+
for (const rawOptionsIdx in rawOptionsArr) {
53+
const rawOptions = rawOptionsArr[rawOptionsIdx]
5454

55-
for (const optionsIndex in rawOptionsArray) {
56-
validate(optionsSchema, rawOptionsArray[optionsIndex], { name: loaderName })
55+
validate(optionsSchema, rawOptions, { name: loaderName })
5756

58-
optionsArray[optionsIndex] = Object.assign({}, defaultOptions, rawOptionsArray[optionsIndex])
57+
optionsArr[rawOptionsIdx] = Object.assign({}, defaultOptions, rawOptions)
5958
}
6059

61-
return optionsArray
60+
return optionsArr
6261
}
6362

64-
module.exports = getOptionsArray
63+
module.exports = getOptionsArr

lib/loader.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const getOptionsArr = require('./getOptionsArr')
2+
const replace = require('./replace')
3+
4+
const loaderName = 'string-replace-loader'
5+
6+
function loader (source, map) {
7+
this.cacheable()
8+
9+
const optionsArr = getOptionsArr(loaderName, this)
10+
11+
let newSource = source
12+
for (const options of optionsArr) {
13+
newSource = replace(newSource, options, this)
14+
}
15+
16+
this.callback(null, newSource, map)
17+
}
18+
19+
module.exports = loader

lib/processChunk.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

lib/replace.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
function replace (source, options, context) {
32
const { flags, strict } = options
43

0 commit comments

Comments
 (0)