Skip to content

Commit 633e32b

Browse files
dmitmelVlad Zhukov
authored andcommitted
Remove the old fileType API (#260)
1 parent 3afae5a commit 633e32b

File tree

20 files changed

+30
-424
lines changed

20 files changed

+30
-424
lines changed

docs/BLOCK-CREATION.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,7 @@ function sampleBlock () {
108108

109109
The context object is a metadata object that is passed to every block. It is meant to contain any kind of data that is needed for webpack config creation, but not part of the webpack config itself.
110110

111-
Initially it will contain the `fileType` mapping and a `webpack` instance. If you are using [hooks](#hooks) you might want to put custom metadata into the context and use it in the `post` hook.
112-
113-
### context.fileType
114-
115-
*Deprecated. This feature will be removed soon. Use `match()` and `context.match` instead.*
116-
117-
The `context.fileType` is a mapping from MIME type (`application/javascript`, `text/css`, ...) to a regular expression used for matching filenames. You can find the default file types and the extensions they match [here](https://github.com/andywer/webpack-blocks/blob/master/packages/core/lib/defaultFileTypes.js).
111+
Initially it will contain a `webpack` instance. If you are using [hooks](#hooks) you might want to put custom metadata into the context and use it in the `post` hook.
118112

119113
### context.match
120114

packages/assets/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# @webpack-blocks/assets - Changelog
22

3+
## Next Release
4+
5+
- Remove deprecated `fileType` API ([#260](https://github.com/andywer/webpack-blocks/issues/260))
6+
37
## 1.0.0-rc
48

59
- Added a `styleLoader` option to `css()` and `css.modules()` blocks.

packages/assets/__tests__/css.test.js

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -96,46 +96,3 @@ test('style-loader can be disabled', t => {
9696
}
9797
])
9898
})
99-
100-
test('deprecated css(<fileType>) still works', t => {
101-
const config = createConfig({}, [
102-
css('text/x-sass')
103-
])
104-
105-
t.deepEqual(config.module.rules, [
106-
{
107-
test: /\.(sass|scss)$/,
108-
use: [
109-
{
110-
loader: 'style-loader',
111-
options: {}
112-
}, {
113-
loader: 'css-loader',
114-
options: {}
115-
}
116-
]
117-
}
118-
])
119-
})
120-
121-
test('deprecated css(<fileType>, { exclude }) still works', t => {
122-
const config = createConfig({}, [
123-
css('text/x-sass', { exclude: /node_modules/ })
124-
])
125-
126-
t.deepEqual(config.module.rules, [
127-
{
128-
test: /\.(sass|scss)$/,
129-
exclude: /node_modules/,
130-
use: [
131-
{
132-
loader: 'style-loader',
133-
options: {}
134-
}, {
135-
loader: 'css-loader',
136-
options: {}
137-
}
138-
]
139-
}
140-
])
141-
})

packages/assets/__tests__/file.test.js

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -46,42 +46,3 @@ test('file() works with options and match()', t => {
4646
}
4747
])
4848
})
49-
50-
test('deprecated file(<fileType>) still works', t => {
51-
const config = createConfig({}, [
52-
file('image')
53-
])
54-
55-
t.deepEqual(config.module.rules, [
56-
{
57-
test: /\.(gif|ico|jpg|jpeg|png|svg|webp)$/,
58-
use: [
59-
{
60-
loader: 'file-loader',
61-
options: {}
62-
}
63-
]
64-
}
65-
])
66-
})
67-
68-
test('deprecated file(<fileType>, { exclude }) still works', t => {
69-
const config = createConfig({}, [
70-
file('image', { exclude: /node_modules/ })
71-
])
72-
73-
t.deepEqual(config.module.rules, [
74-
{
75-
test: /\.(gif|ico|jpg|jpeg|png|svg|webp)$/,
76-
exclude: /node_modules/,
77-
use: [
78-
{
79-
loader: 'file-loader',
80-
options: {
81-
exclude: /node_modules/
82-
}
83-
}
84-
]
85-
}
86-
])
87-
})

packages/assets/__tests__/url.test.js

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -46,42 +46,3 @@ test('url() works with options and match()', t => {
4646
}
4747
])
4848
})
49-
50-
test('deprecated url(<fileType>) still works', t => {
51-
const config = createConfig({}, [
52-
url('image')
53-
])
54-
55-
t.deepEqual(config.module.rules, [
56-
{
57-
test: /\.(gif|ico|jpg|jpeg|png|svg|webp)$/,
58-
use: [
59-
{
60-
loader: 'url-loader',
61-
options: {}
62-
}
63-
]
64-
}
65-
])
66-
})
67-
68-
test('deprecated url(<fileType>, { exclude }) still works', t => {
69-
const config = createConfig({}, [
70-
url('image', { exclude: /node_modules/ })
71-
])
72-
73-
t.deepEqual(config.module.rules, [
74-
{
75-
test: /\.(gif|ico|jpg|jpeg|png|svg|webp)$/,
76-
exclude: /node_modules/,
77-
use: [
78-
{
79-
loader: 'url-loader',
80-
options: {
81-
exclude: /node_modules/
82-
}
83-
}
84-
]
85-
}
86-
])
87-
})

packages/assets/lib/compat.js

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

packages/assets/lib/css.js

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
11
const _ = require('lodash')
2-
const { synthesizeMatch } = require('./compat')
32

43
module.exports = css
54
module.exports.modules = cssModules
65

76
/**
8-
* @param {string} [fileType] Deprecated.
97
* @param {object} [options] You can pass all css-loader options.
108
* @param {object} [options.styleLoader] style-loader options. If set to 'false' the 'style-loader' won't be added.
119
* @return {Function}
1210
* @see https://github.com/webpack-contrib/css-loader
1311
*/
14-
function css (fileType, options = {}) {
15-
if (fileType && typeof fileType === 'object' && Object.keys(options).length === 0) {
16-
options = fileType
17-
fileType = null
18-
}
19-
if (fileType || options.exclude || options.include) {
20-
console.warn(`css(): You are using the deprecated 'fileType' parameter, 'options.exclude' or 'options.include'. Use match() instead.`)
21-
}
22-
23-
const cssOptions = _.omit(options, ['exclude', 'include', 'styleLoader'])
12+
function css (options = {}) {
13+
const cssOptions = _.omit(options, ['styleLoader'])
2414
const loaders = [{ loader: 'css-loader', options: cssOptions }]
2515

2616
if (options.styleLoader !== false) {
@@ -33,31 +23,20 @@ function css (fileType, options = {}) {
3323
test: /\.css$/,
3424
use: loaders
3525
},
36-
// for API backwards compatibility only
37-
synthesizeMatch(context.fileType(fileType || 'text/css'), options),
3826
context.match
3927
)
4028
)
4129
}
4230

4331
/**
44-
* @param {string} [fileType] Deprecated.
4532
* @param {object} [options] You can pass all css-loader options.
4633
* @param {number} [options.importLoaders] Defaults to 1.
4734
* @param {string} [options.localIdentName] Defaults to '[hash:base64:10]' in production, '[name]--[local]--[hash:base64:5]' in development.
4835
* @param {object} [options.styleLoader] style-loader options. If set to 'false' the 'style-loader' won't be added.
4936
* @return {Function}
5037
* @see https://github.com/webpack-contrib/css-loader
5138
*/
52-
function cssModules (fileType, options = {}) {
53-
if (fileType && typeof fileType === 'object' && Object.keys(options).length === 0) {
54-
options = fileType
55-
fileType = null
56-
}
57-
if (fileType || options.exclude || options.include) {
58-
console.warn(`css.modules(): You are using the deprecated 'fileType' parameter, 'options.exclude' or 'options.include'. Use match() instead.`)
59-
}
60-
39+
function cssModules (options = {}) {
6140
const defaultCssOptions = {
6241
modules: true,
6342
importLoaders: 1,
@@ -78,8 +57,6 @@ function cssModules (fileType, options = {}) {
7857
test: /\.css$/,
7958
use: loaders
8059
},
81-
// for API backwards compatibility only
82-
synthesizeMatch(context.fileType(fileType || 'text/css'), options),
8360
context.match
8461
)
8562
)

packages/assets/lib/file.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
1-
const { synthesizeMatch } = require('./compat')
2-
31
module.exports = file
42

53
/**
6-
* @param {string} [fileType] Deprecated.
74
* @param {object} [options] You can pass all file-loader options.
85
* @return {Function}
96
* @see https://github.com/webpack-contrib/file-loader
107
*/
11-
function file (fileType, options = {}) {
8+
function file (options = {}) {
129
return (context, util) => {
13-
if (fileType && typeof fileType === 'object' && Object.keys(options).length === 0) {
14-
options = fileType
15-
fileType = null
16-
}
17-
if (fileType || options.exclude || options.include) {
18-
console.warn(`file(): You are using the deprecated 'fileType' parameter, 'options.exclude' or 'options.include'. Use match() instead.`)
19-
} else if (!context.match) {
10+
if (!context.match) {
2011
throw new Error(
2112
`The file() block can only be used in combination with match(). ` +
2213
`Use match() to state on which files to apply the file loader.`
@@ -30,8 +21,6 @@ function file (fileType, options = {}) {
3021
{ loader: 'file-loader', options }
3122
]
3223
},
33-
// for API backwards compatibility only
34-
synthesizeMatch(fileType && context.fileType(fileType), options),
3524
context.match
3625
)
3726
)

packages/assets/lib/url.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
1-
const { synthesizeMatch } = require('./compat')
2-
31
module.exports = url
42

53
/**
6-
* @param {string} [fileType] Deprecated.
74
* @param {object} [options] You can pass all url-loader options.
85
* @return {Function}
96
* @see https://github.com/webpack-contrib/url-loader
107
*/
11-
function url (fileType, options = {}) {
8+
function url (options = {}) {
129
return (context, util) => {
13-
if (fileType && typeof fileType === 'object' && Object.keys(options).length === 0) {
14-
options = fileType
15-
fileType = null
16-
}
17-
if (fileType || options.exclude || options.include) {
18-
console.warn(`url(): You are using the deprecated 'fileType' parameter, 'options.exclude' or 'options.include'. Use match() instead.`)
19-
} else if (!context.match) {
10+
if (!context.match) {
2011
throw new Error(
2112
`The url() block can only be used in combination with match(). ` +
2213
`Use match() to state on which files to apply the url loader.`
@@ -30,8 +21,6 @@ function url (fileType, options = {}) {
3021
{ loader: 'url-loader', options }
3122
]
3223
},
33-
// for API backwards compatibility only
34-
synthesizeMatch(fileType && context.fileType(fileType), options),
3524
context.match
3625
)
3726
)

packages/core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# @webpack-blocks/core - Changelog
22

3+
## Next Release
4+
5+
- Remove deprecated `fileType` API ([#260](https://github.com/andywer/webpack-blocks/issues/260))
6+
37
## 1.0.0
48

59
- Added `when()` ([#242](https://github.com/andywer/webpack-blocks/issues/242))

0 commit comments

Comments
 (0)