Skip to content

Commit

Permalink
refactor: rename to impound
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Aug 29, 2024
1 parent 39d3e58 commit 3d48f26
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/---bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ body:
required: true
attributes:
label: 🛠️ To reproduce
description: A reproduction of the bug via https://stackblitz.com/github/unjs/custodio/tree/main/playground
description: A reproduction of the bug via https://stackblitz.com/github/unjs/impound/tree/main/playground
placeholder: https://stackblitz.com/[...]
- type: textarea
validations:
Expand Down
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# custodio
# impound

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
Expand All @@ -13,17 +13,17 @@ Install package:

```sh
# npm
npm install custodio
npm install impound
```

```js
import { dirname } from 'node:path'
import { CustodioPlugin } from 'custodio'
import { ImpoundPlugin } from 'impound'

const build = await rollup({
input: 'entry.js',
plugins: [
CustodioPlugin.rollup({
ImpoundPlugin.rollup({
cwd: dirname(import.meta.url),
include: [/src\/*/],
patterns: [
Expand Down Expand Up @@ -57,11 +57,11 @@ Published under [MIT License](./LICENCE).
<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/custodio?style=flat-square
[npm-version-href]: https://npmjs.com/package/custodio
[npm-downloads-src]: https://img.shields.io/npm/dm/custodio?style=flat-square
[npm-downloads-href]: https://npmjs.com/package/custodio
[github-actions-src]: https://img.shields.io/github/actions/workflow/status/unjs/custodio/ci.yml?branch=main&style=flat-square
[github-actions-href]: https://github.com/unjs/custodio/actions?query=workflow%3Aci
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/custodio/main?style=flat-square
[codecov-href]: https://codecov.io/gh/unjs/custodio
[npm-version-src]: https://img.shields.io/npm/v/impound?style=flat-square
[npm-version-href]: https://npmjs.com/package/impound
[npm-downloads-src]: https://img.shields.io/npm/dm/impound?style=flat-square
[npm-downloads-href]: https://npmjs.com/package/impound
[github-actions-src]: https://img.shields.io/github/actions/workflow/status/unjs/impound/ci.yml?branch=main&style=flat-square
[github-actions-href]: https://github.com/unjs/impound/actions?query=workflow%3Aci
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/impound/main?style=flat-square
[codecov-href]: https://codecov.io/gh/unjs/impound
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "custodio",
"name": "impound",
"type": "module",
"version": "0.0.1",
"packageManager": "[email protected]",
"description": "Builder-agnostic plugin to allow restricting import patterns in certain parts of your code-base.",
"license": "MIT",
"repository": "unjs/custodio",
"repository": "unjs/impound",
"sideEffects": false,
"exports": {
".": "./dist/index.js"
Expand Down Expand Up @@ -49,7 +49,7 @@
"vitest": "latest"
},
"resolutions": {
"custodio": "link:."
"impound": "link:."
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
Expand Down
4 changes: 2 additions & 2 deletions playground/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { dirname } from 'node:path'
import { CustodioPlugin } from 'custodio'
import { ImpoundPlugin } from 'impound'
import { rollup } from 'rollup'

await rollup({
input: 'src/index.js',
plugins: [
CustodioPlugin.rollup({
ImpoundPlugin.rollup({
cwd: dirname(import.meta.url),
include: [/src\/*/],
patterns: [
Expand Down
2 changes: 1 addition & 1 deletion playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dev": "node index.js"
},
"dependencies": {
"custodio": "latest",
"impound": "latest",
"rollup": "^4.21.1"
}
}
4 changes: 2 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { resolvePath } from 'mlly'
import { isAbsolute, join, relative } from 'pathe'
import { createFilter } from '@rollup/pluginutils'

export interface CustodioOptions {
export interface ImpoundOptions {
/** An array of patterns of importers to apply the import protection rules to. */
include?: Array<string | RegExp>
/** An array of patterns of importers where the import protection rules explicitly do not apply. */
Expand All @@ -20,12 +20,12 @@ export interface CustodioOptions {

const RELATIVE_IMPORT_RE = /^\.\.?\//

export const CustodioPlugin = createUnplugin((options: CustodioOptions) => {
export const ImpoundPlugin = createUnplugin((options: ImpoundOptions) => {
const filter = createFilter(options.include, options.exclude)
const proxy = resolvePath('unenv/runtime/mock/proxy', { url: import.meta.url })

return {
name: 'custodio',
name: 'impound',
enforce: 'pre',
resolveId(id, importer) {
if (!importer || !filter(importer)) {
Expand Down
18 changes: 9 additions & 9 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { describe, expect, it } from 'vitest'
import { rollup } from 'rollup'
import type { RollupError } from 'rollup'
import { CustodioPlugin } from '../src'
import type { CustodioOptions } from '../src'
import { ImpoundPlugin } from '../src'
import type { ImpoundOptions } from '../src'

describe('custodio plugin', () => {
describe('impound plugin', () => {
const code = (id: string) => `import thing from "${id}";console.log(thing)`

it('prevents importing a disallowed pattern', async () => {
const result = await process(code('bar'), { patterns: [['bar']] }) as RollupError
expect(result.message).toMatchInlineSnapshot(`"[plugin custodio] Invalid import [importing \`bar\` from \`entry.js\`]"`)
expect(result.message).toMatchInlineSnapshot(`"[plugin impound] Invalid import [importing \`bar\` from \`entry.js\`]"`)
})

it('should work with relative imports', async () => {
const result = await process(code('./bar.js'), { patterns: [['bar.js']] }) as RollupError
expect(result.message).toMatchInlineSnapshot(`"[plugin custodio] Invalid import [importing \`bar.js\` from \`entry.js\`]"`)
expect(result.message).toMatchInlineSnapshot(`"[plugin impound] Invalid import [importing \`bar.js\` from \`entry.js\`]"`)
})

it('should handle absolute paths', async () => {
const result = await process(code('/root/bar.js'), { cwd: '/root', patterns: [['bar.js']] }) as RollupError
expect(result.message).toMatchInlineSnapshot(`"[plugin custodio] Invalid import [importing \`bar.js\` from \`entry.js\`]"`)
expect(result.message).toMatchInlineSnapshot(`"[plugin impound] Invalid import [importing \`bar.js\` from \`entry.js\`]"`)
})

it(`doesn't apply rule to excluded files`, async () => {
Expand All @@ -33,18 +33,18 @@ describe('custodio plugin', () => {

it('provides a helpful error message when importing a disallowed pattern', async () => {
const result = await process(code('bar'), { patterns: [['bar', '"bar" is a dangerous library and should never be used.']] }) as RollupError
expect(result.message).toMatchInlineSnapshot(`"[plugin custodio] "bar" is a dangerous library and should never be used. [importing \`bar\` from \`entry.js\`]"`)
expect(result.message).toMatchInlineSnapshot(`"[plugin impound] "bar" is a dangerous library and should never be used. [importing \`bar\` from \`entry.js\`]"`)
})
})

async function process(code: string, opts: CustodioOptions) {
async function process(code: string, opts: ImpoundOptions) {
const libs = ['foo', 'bar']

try {
const build = await rollup({
input: 'entry.js',
plugins: [
CustodioPlugin.rollup(opts),
ImpoundPlugin.rollup(opts),
{
name: 'entry',
load: id => id === 'entry.js' ? code : undefined,
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defineConfig } from 'vitest/config'
export default defineConfig({
resolve: {
alias: {
custodio: fileURLToPath(
impound: fileURLToPath(
new URL('./src/index.ts', import.meta.url).href,
),
},
Expand Down

0 comments on commit 3d48f26

Please sign in to comment.