├── test ├── fixtures │ ├── array │ │ ├── src │ │ │ ├── ignored.json │ │ │ ├── ignored.md │ │ │ ├── preserved.css │ │ │ ├── preserved.md │ │ │ ├── removed.js │ │ │ └── removed.yaml │ │ └── expected │ │ │ ├── preserved.css │ │ │ └── preserved.md │ ├── object │ │ ├── src │ │ │ ├── ignored.json │ │ │ ├── ignored.md │ │ │ ├── preserved.css │ │ │ ├── preserved.md │ │ │ ├── removed.js │ │ │ └── removed.yaml │ │ └── expected │ │ │ ├── preserved.css │ │ │ └── preserved.md │ ├── other │ │ ├── src │ │ │ ├── preserved.css │ │ │ └── preserved.md │ │ └── expected │ │ │ ├── preserved.css │ │ │ └── preserved.md │ ├── string │ │ ├── src │ │ │ ├── ignored.json │ │ │ ├── ignored.md │ │ │ ├── preserved.css │ │ │ └── preserved.md │ │ └── expected │ │ │ ├── preserved.css │ │ │ └── preserved.md │ └── string-tilda │ │ ├── src │ │ ├── preserved.md │ │ ├── preserved.css │ │ └── preserved.md~ │ │ └── expected │ │ ├── preserved.md │ │ └── preserved.css └── index.js ├── .prettierignore ├── .npmrc ├── .prettierrc.yml ├── .gitignore ├── .editorconfig ├── lib └── index.d.ts ├── .gitattributes ├── .release-it.json ├── LICENSE ├── eslint.config.js ├── .github └── workflows │ └── test.yml ├── src └── index.js ├── package.json ├── README.md └── CHANGELOG.md /test/fixtures/array/src/ignored.json: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/array/src/ignored.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/array/src/preserved.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/array/src/preserved.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/array/src/removed.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/array/src/removed.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/object/src/ignored.json: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/object/src/ignored.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/object/src/preserved.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/object/src/preserved.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/object/src/removed.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/object/src/removed.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/other/src/preserved.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/other/src/preserved.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/string/src/ignored.json: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/string/src/ignored.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/string/src/preserved.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/string/src/preserved.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/array/expected/preserved.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/array/expected/preserved.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/object/expected/preserved.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/object/expected/preserved.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/other/expected/preserved.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/other/expected/preserved.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/string-tilda/src/preserved.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/string/expected/preserved.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/string/expected/preserved.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/string-tilda/expected/preserved.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/string-tilda/src/preserved.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/string-tilda/src/preserved.md~: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/fixtures/string-tilda/expected/preserved.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | test/fixtures/** 2 | coverage/** 3 | package-lock.json 4 | lib -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock.json = false 2 | sign-git-tag = true 3 | message = Bump package.json to %s -------------------------------------------------------------------------------- /.prettierrc.yml: -------------------------------------------------------------------------------- 1 | trailingComma: none 2 | tabWidth: 2 3 | semi: false 4 | singleQuote: true 5 | bracketSpacing: true 6 | arrowParens: always 7 | printWidth: 120 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | npm-debug.log* 2 | .npm 3 | *.tgz 4 | .eslintcache 5 | coverage 6 | coverage.info 7 | test/fixtures/*/build 8 | node_modules 9 | lib 10 | !lib/*.d.ts -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | charset = utf-8 3 | 4 | [*.{js,json,yml}] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /lib/index.d.ts: -------------------------------------------------------------------------------- 1 | import { Plugin } from 'metalsmith'; 2 | 3 | export default remove; 4 | export type Options = { 5 | patterns: string[]; 6 | }; 7 | 8 | /** 9 | * A Metalsmith plugin to remove files from the build 10 | * 11 | * @example 12 | * // remove all dotfiles that are direct children of metalsmith.source() 13 | * metalsmith.use(remove('.*')) 14 | * // remove all JSON files 15 | * metalsmith.use(remove(['**\/*.json'])) 16 | */ 17 | declare function remove( 18 | /** One or more [glob patterns](https://en.wikipedia.org/wiki/Glob_(programming)) */ 19 | options?: string | string[] | Options 20 | ): Plugin; 21 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Automatically normalize line endings for all text-based files 2 | # http://git-scm.com/docs/gitattributes#_end_of_line_conversion 3 | * text=auto 4 | 5 | # For the following file types, normalize line endings to LF on 6 | # checkin and prevent conversion to CRLF when they are checked out 7 | # (this is required in order to prevent newline related issues like, 8 | # for example, after the build script is run) 9 | .* text eol=lf 10 | *.css text eol=lf 11 | *.html text eol=lf 12 | *.js text eol=lf 13 | *.json text eol=lf 14 | *.yaml text eol=lf 15 | *.md text eol=lf 16 | *.sh text eol=lf 17 | *.txt text eol=lf 18 | *.xml text eol=lf -------------------------------------------------------------------------------- /.release-it.json: -------------------------------------------------------------------------------- 1 | { 2 | "hooks": { 3 | "before:init": ["npm run lint", "npm test", "npm run build"], 4 | "after:bump": "auto-changelog --sort-commits date-desc -p --commit-limit false --ignore-commit-pattern '^((dev|chore|ci):|Release)'", 5 | "after:npm:bump": "npm pack", 6 | "after:release": "echo Successfully released ${name} v${version} to ${repo.repository}." 7 | }, 8 | "git": { 9 | "commitMessage": "Release ${version}", 10 | "commitArgs": ["-S"], 11 | "tagAnnotation": "Release ${version}", 12 | "tagArgs": ["-s"], 13 | "changelog": "auto-changelog -u --commit-limit false --ignore-commit-pattern '^((dev|chore|ci):|Release)' --stdout -t https://raw.githubusercontent.com/release-it/release-it/master/templates/changelog-compact.hbs" 14 | }, 15 | "npm": { 16 | "publish": false 17 | }, 18 | "github": { 19 | "release": true, 20 | "releaseName": "@metalsmith/remove ${version}", 21 | "tokenRef": "GITHUB_TOKEN", 22 | "assets": ["metalsmith-remove-${version}.tgz"] 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 webketje 4 | Copyright (c) 2014-2021 Segment 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. -------------------------------------------------------------------------------- /eslint.config.js: -------------------------------------------------------------------------------- 1 | import js from '@eslint/js' 2 | import globals from 'globals' 3 | import prettier from 'eslint-config-prettier' 4 | import pluginImport from 'eslint-plugin-import' 5 | import pluginNode from 'eslint-plugin-n' 6 | 7 | const config = [ 8 | { 9 | ignores: ['lib'], 10 | languageOptions: { 11 | globals: { 12 | ...globals.node 13 | }, 14 | 15 | ecmaVersion: 2020, 16 | sourceType: 'module' 17 | }, 18 | 19 | rules: { 20 | ...js.configs.recommended.rules, 21 | 'no-console': 'error', 22 | 'prefer-const': 'error', 23 | 'no-var': 'error', 24 | 'no-use-before-define': 'error', 25 | 'no-unused-vars': [ 26 | 'error', 27 | { 28 | argsIgnorePattern: '^_', 29 | varsIgnorePattern: '^_', 30 | caughtErrorsIgnorePattern: '^_' 31 | } 32 | ], 33 | 'no-await-in-loop': 'error', 34 | 'n/exports-style': [0, 'error'], 35 | 'import/first': 'error', 36 | 'import/no-anonymous-default-export': 'error', 37 | 'import/no-unassigned-import': 'error', 38 | 'import/no-internal-modules': [ 39 | 'error', 40 | { 41 | allow: ['src/**'] 42 | } 43 | ] 44 | }, 45 | plugins: { 46 | import: pluginImport, 47 | n: pluginNode, 48 | prettier: prettier 49 | } 50 | }, 51 | { 52 | files: ['test/{**/,}*.js'], 53 | languageOptions: { 54 | globals: { ...globals.mocha } 55 | } 56 | } 57 | ] 58 | 59 | export default config 60 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: ['**'] 5 | pull_request: 6 | branches: ['main'] 7 | 8 | jobs: 9 | pre-test: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v3 13 | - uses: actions/setup-node@v3 14 | with: 15 | cache: 'npm' 16 | 17 | - run: npm install 18 | - run: npm run format:check 19 | - run: npm run lint:check 20 | 21 | branch-test: 22 | if: github.ref_name != 'main' && success() 23 | needs: pre-test 24 | runs-on: ${{ matrix.os }} 25 | strategy: 26 | matrix: 27 | os: ['ubuntu-latest', 'windows-latest'] 28 | node: ['14.18.0'] 29 | name: Testing Node ${{ matrix.node }} on ${{ matrix.os }} 30 | steps: 31 | - uses: actions/checkout@v3 32 | - uses: actions/setup-node@v3 33 | with: 34 | cache: 'npm' 35 | 36 | - run: npm install 37 | - run: npm test 38 | 39 | test: 40 | if: github.ref_name == 'main' && success() 41 | needs: pre-test 42 | runs-on: ${{ matrix.os }} 43 | strategy: 44 | matrix: 45 | os: ['ubuntu-latest', 'windows-latest'] 46 | node: ['14.18.0', '16.0', '18.0', '20.0'] 47 | name: Testing Node ${{ matrix.node }} on ${{ matrix.os }} 48 | steps: 49 | - uses: actions/checkout@v3 50 | - uses: actions/setup-node@v3 51 | with: 52 | node-version: ${{ matrix.node }} 53 | cache: 'npm' 54 | 55 | - run: npm install 56 | - run: npm test 57 | - if: matrix.os == 'ubuntu-latest' && matrix.node == '18' 58 | run: npm run coverage 59 | - if: matrix.os == 'ubuntu-latest' && matrix.node == '18' 60 | uses: coverallsapp/github-action@v2 61 | with: 62 | file: coverage.info 63 | format: lcov 64 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | function normalizeOptions(options) { 4 | if ('string' == typeof options) { 5 | options = [options] 6 | } 7 | if (Array.isArray(options)) { 8 | options = { patterns: options } 9 | } 10 | options = options || {} 11 | return options 12 | } 13 | 14 | /** 15 | * 16 | * @typedef {Object} Options 17 | * @property {String[]} patterns 18 | */ 19 | 20 | /** 21 | * A Metalsmith plugin to remove files from the build 22 | * 23 | * @param {String|String[]|Options} [options] One or more [glob patterns](https://en.wikipedia.org/wiki/Glob_(programming)) 24 | * @return {import('metalsmith').Plugin} 25 | * @example 26 | * // remove all dotfiles that are direct children of metalsmith.source() 27 | * metalsmith.use(remove('.*')) 28 | * // remove all JSON files 29 | * metalsmith.use(remove(['**\/*.json'])) 30 | */ 31 | function remove(options) { 32 | return function remove(files, metalsmith, done) { 33 | const patterns = normalizeOptions(options).patterns || [] 34 | const matches = metalsmith.match(patterns, Object.keys(files)) 35 | const debug = metalsmith.debug('@metalsmith/remove') 36 | 37 | if (!matches.length) { 38 | debug.warn('No files marked for removal') 39 | } else { 40 | debug('Marked %s files for removal', matches.length) 41 | } 42 | 43 | for (let i = 0; i < matches.length; i++) { 44 | const filename = matches[i] 45 | try { 46 | const success = delete files[filename] 47 | // delete returns false in CJS non-strict mode 48 | /* c8 ignore next */ 49 | if (success === false) throw new Error() 50 | debug.info('Removed file "%s"', filename) 51 | // but throws in CJS strict-mode or ESM mode 52 | } catch (_err) { 53 | debug.error('Failed to remove file "%s"', filename) 54 | break 55 | } 56 | } 57 | 58 | done() 59 | } 60 | } 61 | 62 | export default remove 63 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@metalsmith/remove", 3 | "version": "1.4.0", 4 | "description": "A Metalsmith plugin to remove files from the build", 5 | "keywords": [ 6 | "remove", 7 | "metalsmith-plugin", 8 | "metalsmith" 9 | ], 10 | "homepage": "https://github.com/metalsmith/remove#readme", 11 | "bugs": { 12 | "url": "https://github.com/metalsmith/remove/issues" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/metalsmith/remove.git" 17 | }, 18 | "license": "MIT", 19 | "directories": { 20 | "lib": "lib", 21 | "test": "test" 22 | }, 23 | "files": [ 24 | "lib" 25 | ], 26 | "types": "lib/types.d.ts", 27 | "source": "src/index.js", 28 | "main": "lib/index.cjs", 29 | "module": "lib/index.js", 30 | "type": "module", 31 | "exports": { 32 | "require": "./lib/index.cjs", 33 | "import": "./lib/index.js" 34 | }, 35 | "scripts": { 36 | "changelog": "auto-changelog -u --commit-limit false --ignore-commit-pattern '^((dev|chore|ci):|Release)'", 37 | "coverage": "npm test && c8 report --reporter=text-lcov > ./coverage.info", 38 | "format": "prettier --write \"**/*.{yml,md,js,json}\"", 39 | "format:check": "prettier --list-different \"**/*.{yml,md,js,json}\"", 40 | "lint": "eslint --fix .", 41 | "lint:check": "eslint --fix-dry-run .", 42 | "release": "release-it .", 43 | "build": "microbundle --target node -f cjs,esm --strict --generateTypes=false", 44 | "prepack": "npm run build", 45 | "test": "c8 mocha" 46 | }, 47 | "devDependencies": { 48 | "assert-dir-equal": "^1.1.0", 49 | "auto-changelog": "^2.5.0", 50 | "c8": "^10.1.2", 51 | "eslint": "^9.13.0", 52 | "eslint-config-prettier": "^9.1.0", 53 | "eslint-plugin-import": "^2.31.0", 54 | "eslint-plugin-n": "^17.12.0", 55 | "metalsmith": "^2.6.3", 56 | "microbundle": "^0.15.1", 57 | "mocha": "^10.8.2", 58 | "prettier": "^3.3.3", 59 | "release-it": "^17.10.0" 60 | }, 61 | "peerDependencies": { 62 | "metalsmith": "^2.5.0" 63 | }, 64 | "publishConfig": { 65 | "access": "public" 66 | }, 67 | "engines": { 68 | "node": ">=14.18.0" 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # @metalsmith/remove 2 | 3 | A Metalsmith plugin to remove files from the build 4 | 5 | [![metalsmith: core plugin][metalsmith-badge]][metalsmith-url] 6 | [![npm: version][npm-badge]][npm-url] 7 | [![ci: build][ci-badge]][ci-url] 8 | [![code coverage][codecov-badge]][codecov-url] 9 | [![license: MIT][license-badge]][license-url] 10 | 11 | Use `@metalsmith/remove` to discard files from the build output after their metadata and contents have been read and used by plugins. While `Metalsmith#ignore` ignores the matched files completely, `@metalsmith/remove` _only_ removes them at the point the plugin is `use`'d. 12 | 13 | ## Installation 14 | 15 | NPM: 16 | 17 | ```bash 18 | npm install @metalsmith/remove 19 | ``` 20 | 21 | Yarn: 22 | 23 | ```bash 24 | yarn add @metalsmith/remove 25 | ``` 26 | 27 | ## Usage 28 | 29 | Pass the plugin with options to `Metalsmith#use`: 30 | 31 | ```js 32 | import remove from '@metalsmith/remove' 33 | 34 | metalsmith.use(remove('drafts/*')) // single pattern 35 | metalsmith.use(remove(['drafts/*', 'unfinished/*'])) // multiple patterns 36 | ``` 37 | 38 | ### Debug 39 | 40 | To enable debug logs, set the `DEBUG` environment variable to `@metalsmith/remove*`: 41 | 42 | ```js 43 | metalsmith.env('DEBUG', '@metalsmith/remove*') 44 | ``` 45 | 46 | Alternatively you can set `DEBUG` to `@metalsmith/*` to debug all Metalsmith core plugins. 47 | 48 | ### CLI Usage 49 | 50 | To use this plugin with the Metalsmith CLI, add `@metalsmith/remove` to the `plugins` key in your `metalsmith.json` file: 51 | 52 | ```json 53 | { 54 | "plugins": [{ "@metalsmith/remove": "drafts/*" }] 55 | } 56 | ``` 57 | 58 | But you can also pass an array of patterns to ignore: 59 | 60 | ```json 61 | { 62 | "plugins": [{ "@metalsmith/remove": ["drafts/*", "unfinished/*"] }] 63 | } 64 | ``` 65 | 66 | ## License 67 | 68 | [MIT](LICENSE) 69 | 70 | [npm-badge]: https://img.shields.io/npm/v/@metalsmith/remove.svg 71 | [npm-url]: https://www.npmjs.com/package/@metalsmith/remove 72 | [ci-badge]: https://github.com/metalsmith/remove/actions/workflows/test.yml/badge.svg 73 | [ci-url]: https://github.com/metalsmith/remove/actions/workflows/test.yml 74 | [metalsmith-badge]: https://img.shields.io/badge/metalsmith-plugin-green.svg?longCache=true 75 | [metalsmith-url]: https://metalsmith.io 76 | [codecov-badge]: https://img.shields.io/coveralls/github/metalsmith/remove 77 | [codecov-url]: https://coveralls.io/github/metalsmith/remove 78 | [license-badge]: https://img.shields.io/github/license/metalsmith/remove 79 | [license-url]: LICENSE 80 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | import assert from 'node:assert' 2 | import { resolve, dirname } from 'node:path' 3 | import { readFileSync } from 'node:fs' 4 | import { fileURLToPath } from 'node:url' 5 | import equal from 'assert-dir-equal' 6 | import Metalsmith from 'metalsmith' 7 | import remove from '../src/index.js' 8 | 9 | const __dirname = dirname(fileURLToPath(import.meta.url)) 10 | const { name } = JSON.parse(readFileSync(resolve(__dirname, '../package.json'), 'utf-8')) 11 | 12 | function fixture(p) { 13 | return resolve(__dirname, 'fixtures', p) 14 | } 15 | 16 | describe('@metalsmith/remove', function () { 17 | it('should export a named plugin function matching package.json name', function () { 18 | const namechars = name.split('/')[1] 19 | const camelCased = namechars.split('').reduce((str, char, i) => { 20 | str += namechars[i - 1] === '-' ? char.toUpperCase() : char === '-' ? '' : char 21 | return str 22 | }, '') 23 | assert.strictEqual(remove().name, camelCased) 24 | }) 25 | 26 | it('should remove files by patterns', function (done) { 27 | const m = Metalsmith(fixture('object')) 28 | .env('DEBUG', '@metalsmith/remove*') 29 | .clean(true) 30 | .use( 31 | remove({ 32 | patterns: ['ignored.*', 'removed.*'] 33 | }) 34 | ) 35 | 36 | m.build(function (err) { 37 | if (err) return done(err) 38 | equal(fixture('object/build'), fixture('object/expected')) 39 | done() 40 | }) 41 | }) 42 | 43 | it('should take an array shorthand', function (done) { 44 | const m = Metalsmith(fixture('array')) 45 | .env('DEBUG', '@metalsmith/remove*') 46 | .clean(true) 47 | .use(remove(['ignored.*', 'removed.*'])) 48 | m.build(function (err) { 49 | if (err) return done(err) 50 | equal(fixture('array/build'), fixture('array/expected')) 51 | done() 52 | }) 53 | }) 54 | 55 | it('should take a string shorthand', function (done) { 56 | const m = Metalsmith(fixture('string')).clean(true).use(remove('ignored.*')).env('DEBUG', '@metalsmith/remove*') 57 | m.build(function (err) { 58 | if (err) return done(err) 59 | equal(fixture('string/build'), fixture('string/expected')) 60 | done() 61 | }) 62 | }) 63 | 64 | it('should take a string and ignore tilda', function (done) { 65 | const m = Metalsmith(fixture('string-tilda')).clean(true).use(remove('*~')).env('DEBUG', '@metalsmith/remove*') 66 | m.build(function (err) { 67 | if (err) return done(err) 68 | equal(fixture('string-tilda/build'), fixture('string-tilda/expected')) 69 | done() 70 | }) 71 | }) 72 | 73 | it('should ignore non-string or array inputs', function (done) { 74 | Metalsmith(fixture('other')) 75 | .env('DEBUG', '@metalsmith/remove*') 76 | .use(remove(null)) 77 | .build(function (err) { 78 | if (err) return done(err) 79 | equal(fixture('other/build'), fixture('other/expected')) 80 | done() 81 | }) 82 | }) 83 | 84 | it('should log an error when failing to remove a file from the build', function (done) { 85 | const files = {} 86 | const ms = Metalsmith(fixture('/other')) 87 | const debuggr = () => {} 88 | ms.debug = () => debuggr 89 | let msg 90 | debuggr.error = (log, arg) => { 91 | msg = log.replace('%s', arg) 92 | } 93 | debuggr.warn = () => {} 94 | debuggr.info = () => {} 95 | Object.defineProperty(files, 'notwritable', { 96 | value: 'fixed', 97 | writable: false, 98 | configurable: false, 99 | enumerable: true 100 | }) 101 | remove('**')(files, ms, (err) => { 102 | if (err) done(err) 103 | assert.strictEqual(msg, 'Failed to remove file "notwritable"') 104 | done() 105 | }) 106 | }) 107 | }) 108 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### Changelog 2 | 3 | All notable changes to this project will be documented in this file. Dates are displayed in UTC. 4 | 5 | Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). 6 | 7 | #### [v1.4.0](https://github.com/metalsmith/remove/compare/v1.3.0...v1.4.0) 8 | 9 | - Adds engines.node specifier to package.json, drops support for Node <= 14.14.0 (Node 12 EOL 2023-04-30) [`7d71cb0`](https://github.com/metalsmith/remove/commit/7d71cb071d59cbbdb15d0beea4dcfbc11a4c7da8) 10 | - Adds JsDoc example usage [`8927ab3`](https://github.com/metalsmith/remove/commit/8927ab328407469d8b241b09f228b14f78c56544) 11 | - Includes source maps in lib for better debugging [`49639e7`](https://github.com/metalsmith/remove/commit/49639e7d1aefa0a54ffe20d43f8b55ed8b9c4c88) 12 | 13 | #### [v1.3.0](https://github.com/metalsmith/remove/compare/v1.2.1...v1.3.0) 14 | 15 | > 3 December 2022 16 | 17 | - Updates readme debug section [`d47da9a`](https://github.com/metalsmith/remove/commit/d47da9add664c5adfc806a38ff0171e11a4c2e98) 18 | - Logs an error when file delete fails [`c46614a`](https://github.com/metalsmith/remove/commit/c46614a59086cd81c8555f00f5efeb9fb5f5e3c6) 19 | - Replaces debug with metalsmith.debug [`a17e4ba`](https://github.com/metalsmith/remove/commit/a17e4ba6c8dca9fed33023ae5542edd89cabf7a1) 20 | - Enhanced types and rename default export to 'remove' [`8950b05`](https://github.com/metalsmith/remove/commit/8950b05817770599122facedd377c63fd7bf1919) 21 | 22 | #### [v1.2.1](https://github.com/metalsmith/remove/compare/v1.2.0...v1.2.1) 23 | 24 | > 7 August 2022 25 | 26 | - Fixes #26: incorrect export lib/index.mjs [`#26`](https://github.com/metalsmith/remove/issues/26) 27 | 28 | #### [v1.2.0](https://github.com/metalsmith/remove/compare/v1.1.2...v1.2.0) 29 | 30 | > 6 August 2022 31 | 32 | - Added Typescript types [`47a6232`](https://github.com/metalsmith/remove/commit/47a623206e8ab5d30ce6d2a3c6e0829ee05a6114) 33 | - Adds dual bundled ESM/CJS, removes setImmediate [`9111793`](https://github.com/metalsmith/remove/commit/9111793930d1f7b0ba5cc60bb2eff8257ea7b2cf) 34 | 35 | #### [v1.1.2](https://github.com/metalsmith/remove/compare/v1.1.1...v1.1.2) 36 | 37 | > 20 February 2022 38 | 39 | - remove micromatch, use metalsmith.match [`#23`](https://github.com/metalsmith/remove/pull/23) 40 | - Resolves #22: remove micromatch, use metalsmith.match [`#22`](https://github.com/metalsmith/remove/issues/22) 41 | 42 | #### [v1.1.1](https://github.com/metalsmith/remove/compare/v1.1.0...v1.1.1) 43 | 44 | > 6 January 2022 45 | 46 | - Fixes micromatch behavior: dot:true + chore: run format [`5e8a158`](https://github.com/metalsmith/remove/commit/5e8a1589009a659c320f1fbb64c6360bd3ab5744) 47 | - Fix for proper windows path handling [`cf35a7a`](https://github.com/metalsmith/remove/commit/cf35a7ad839f278d3620c3d09428f40ce8d3929e) 48 | - Fixes typo's in package.json/ README.md [`6850479`](https://github.com/metalsmith/remove/commit/685047988944e8c713feb50e5cdc1e1bd54f8ae7) 49 | 50 | #### [v1.1.0](https://github.com/metalsmith/remove/compare/v1.0.0...v1.1.0) 51 | 52 | > 17 December 2021 53 | 54 | - Update multimatch to resolve deprecated dependency [`#16`](https://github.com/metalsmith/remove/pull/16) 55 | - Fixes #21 - Add debug logs [`#21`](https://github.com/metalsmith/remove/issues/21) 56 | - Resolves #20 - swap multimatch for micromatch [`#20`](https://github.com/metalsmith/remove/issues/20) 57 | - Fixes #19 - correct JSDoc types + named plugin [`#19`](https://github.com/metalsmith/remove/issues/19) 58 | - Resolves #17 - rename plugin 'ignore' -> 'remove' [`#17`](https://github.com/metalsmith/remove/issues/17) 59 | - Resolves #18 - Aligned to org core plugin setup [`#18`](https://github.com/metalsmith/remove/issues/18) 60 | - Test for files ending with ~ (tilda) [`#3`](https://github.com/metalsmith/remove/issues/3) 61 | - Tests: Use const [`c103fca`](https://github.com/metalsmith/remove/commit/c103fca92b43ca18dc043a5e8e916b3dc3973aef) 62 | - Update Readme.md [`c97ccc0`](https://github.com/metalsmith/remove/commit/c97ccc019e0eb857b90ab3716821a5678129194c) 63 | - Tests: added missing config [`69c5ecc`](https://github.com/metalsmith/remove/commit/69c5eccc1226ead6e63619914908dcf88f8a7740) 64 | - Packages: updated and added travis, eslint, and prettier [`7326e00`](https://github.com/metalsmith/remove/commit/7326e0000bca2aca26ddee5d62fa509743148bb1) 65 | 66 | ### [v1.0.0](https://github.com/metalsmith/remove/compare/0.1.2...v1.0.0) 67 | 68 | > 17 July 2018 69 | 70 | - Use multimatch() with the file list [`#4`](https://github.com/metalsmith/remove/pull/4) 71 | - Update multimatch to resolve deprecated dependency [`#11`](https://github.com/metalsmith/remove/pull/11) 72 | - add link to multimatch in readme [`#6`](https://github.com/metalsmith/remove/pull/6) 73 | - Removed unnecessary makefile and updated history [`4631b17`](https://github.com/metalsmith/remove/commit/4631b175efa0e60452dfbc6a0b96b1472f7e9d71) 74 | - Updated Packages [`96ebad7`](https://github.com/metalsmith/remove/commit/96ebad7e52cbc1e0ae032edba69027832cf19100) 75 | 76 | #### [0.1.2](https://github.com/metalsmith/remove/compare/0.1.1...0.1.2) 77 | 78 | > 11 March 2014 79 | 80 | #### [0.1.1](https://github.com/metalsmith/remove/compare/0.1.0...0.1.1) 81 | 82 | > 10 March 2014 83 | 84 | - Fix pattern matching [`#1`](https://github.com/metalsmith/remove/pull/1) 85 | - ocd [`5c2c097`](https://github.com/metalsmith/remove/commit/5c2c097f4685b3c3e29aec813f535f9c8eac5731) 86 | - check length of matches before ignoring [`6704af9`](https://github.com/metalsmith/remove/commit/6704af9a1eebe0b578303408824b23ab39080743) 87 | - clean out build directories for better tests [`7cd0915`](https://github.com/metalsmith/remove/commit/7cd0915d0abf95dd1d67f70eb6f89d932270aeb7) 88 | 89 | #### 0.1.0 90 | 91 | > 7 March 2014 92 | 93 | - swap to multimatch [`0045af4`](https://github.com/metalsmith/remove/commit/0045af4bf864f7eb004be2a3908d35ed847bf380) 94 | - first commit [`4685621`](https://github.com/metalsmith/remove/commit/468562143a2a42af1eb6f2fab9e58858736fce37) 95 | --------------------------------------------------------------------------------