90 Commits
Author SHA1 Message Date
Andrey Sitnik c5fff770ca Limit where source map can be loaded for security reasons 2026-07-12 20:31:03 +00:00
Andrey Sitnik d99a1fed74 Load only .map source maps 2026-04-26 13:44:05 +00:00
Andrey Sitnik 85bf516d71 Move to oxfmt 2026-04-07 16:07:54 +00:00
2f3c759a4b Add Input#document (#1996)
* Add `Input#document`

* Update lib/postcss.d.ts

Co-authored-by: Andrey Sitnik <[email protected]>

* apply suggestion from code review

---------

Co-authored-by: Andrey Sitnik <[email protected]>
2025-01-13 16:12:42 +01:00
Andrey Sitnik 19afb318d6 Sort source code and fix ESLint 2024-08-31 23:26:27 +02:00
Natalie Weizenbaum ff3a71c551 Use ReadonlyArray for argument types that aren't modified
This makes it possible for callers to pass in their own
`ReadonlyArray`s, and implicitly documents that these arguments aren't
modified.
2024-08-19 17:38:40 -07:00
Natalie Weizenbaum 8611913a4f Declare Container.normalize() as a protected method
This allows subclasses to call and override this method. This PR also
adds a shared type declaration for the common argument type used to
add or create new nodes, which eventually gets passed into
`normalize`.
2024-08-08 14:15:39 -07:00
Andrey Sitnik d101a9999f Sort keys 2024-07-29 10:29:05 +00:00
Andrew Ferreira b23224d0a1 Fix ProcessOptions interface 2023-12-01 10:33:53 -03:00
Andrey Sitnik ae4edd5e26 Cast Result.root type from process() options 2023-08-14 20:19:32 +02:00
Andrey Sitnik 89b7f7ac78 Update dependencies and code style 2023-07-06 13:38:48 +02:00
Andrey Sitnik ebff68d8e3 Remove wrong event 2023-05-28 00:51:19 +02:00
Remco Haszing e2b86be4ad Revert some unwanted changes 2023-03-27 18:50:14 +02:00
Remco Haszing f739b0bde1 Use ESM imports in type definitions 2023-03-27 18:45:38 +02:00
Remco Haszing c5275ddc7b Add back support for default in type definitions 2023-03-02 12:35:05 +01:00
Remco Haszing cae533107d Fix type definitions
Many files from postcss are exported. Each of this file is written using
the syntax:

```js
module.exports = Thing
```

This should be typed as:

```ts
export = Thing
```

If such a file needs to export additional types, a namespace should be
used.

However, it was typed as:

```ts
export default thing
```

This was solved at the time in #1459 (by me) by adding the following
code to each module:

```js
Thing.default = Thing
```

Whilst affective at the time, this was not the correct solution. The
introduction of the `"module": "node16"` option in TypeScript made this
issue more apparent. I recommend to remove this in a next semver major
release.

Usage has changed as follows:

**cts**

```jsonc
// tsconfig.json
{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node16"
  }
}
```

```ts
// Old
import postcss = require('postcss')

postcss.default(/* … */)
```

```ts
// New
import postcss = require('postcss')

postcss(/* … */)
```

**cjs**

```jsonc
// tsconfig.json
{
  "compilerOptions": {
    "checkJs": true,
    "module": "commonjs",
    "moduleResolution": "node16"
  }
}
```

```ts
// Old
const postcss = require('postcss')

postcss.default(/* … */)
```

```ts
// New
const postcss = require('postcss')

postcss(/* … */)
```

**mts** / **mjs**

```jsonc
// tsconfig.json
{
  "compilerOptions": {
    "module": "node16"
  }
}
```

```ts
// Old
import postcss from 'postcss'

postcss.default(/* … */)
```

```ts
// New
import postcss from 'postcss'

postcss(/* … */)
```

**bundler**

```jsonc
// tsconfig.json
{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "module": "esnext",
    "moduleResolution": "node16"
  }
}
```

```ts
// Unchanged
import postcss from 'postcss'

postcss(/* … */)
```

**ES module interop** (Not recommended for library code!)

```jsonc
// tsconfig.json
{
  "compilerOptions": {
    "esModuleInterop": true,
    "module": "commonjs",
    "moduleResolution": "node16"
  }
}
```

```ts
// Unchanged
import postcss from 'postcss'

postcss(/* … */)
```

When compiling to CJS, it is still possible to write ESM-like syntax,
for example:

```jsonc
// Same as import postcss = require('postcss')
import * as postcss from 'postcss'
// Named imports from namespaces are allowed
import { root, Root } from 'postcss'
```

The following changes were made to `tsconfig.json`:

- `lib` was specified explicitly. By default, TypeScript includes the
  `dom` types. This is not desirable, it even causes some conflicts with
  types used by Postcss.
- `allowJs` was removed. When this is enabled, TypeScript treats `.d.ts`
  files matching `.js` files as output. This caused some unexpected
  issues where TypeScript simply ignored type errors.
- `skipLibCheck` was removed. Ideally all types just work together. This
  can be added again later if necessary.
- `esModuleInterop` was removed. Enabling this option causes TypeScript
  to allow code that is otherwise invalid. This may be useful for CLIs
  or website, but is dangerous to use for libraries.

Correcting these options also highlighted some issues in the tests.
These have been resolved. `nanodelay@1` has incorrect type definitions,
so it has been marked using `@ts-expect-error` comments.

In `test/errors.ts` were some type errors. These were marked as
`THROWS`, which signals `check-dts` a type error is expected.
This was changed to `@ts-expect-error`, which works too, but it also
works with other TypeScript tooling.

The `Postcss` type was missing some properties. As a side effect of the
corrected types, these are now available. This also affects the `Helper`
type.

Last, but not least, type definitions have been added for `postcss.mjs`.

Closes #1814
2023-02-16 16:17:58 +01:00
43081j a8b2c18feb fix: add Document to result sets and default parser type
Fixes #1667

A `Result` can now contain a root which is ` Document`. For example, a
custom syntax may produce a `Document` containing several nested `Root`
stylesheets.

Similarly, the default type parameter of `Parser` has been updated to
include `Document` since custom syntaxes must account for this anyway.
2021-11-16 22:17:34 +00:00
Andrey Sitnik 3261a7ed1d Export Processor type 2021-11-16 16:43:49 +01:00
Andrey SitnikandGitHub 2c6777648a Merge pull request #1582 from hudochenkov/add-document-node-1498
Add Document node and related API (#1498)
2021-05-18 20:46:25 -04:00
Aleks Hudochenkov eeea51219e Fix Parser type 2021-05-18 23:48:26 +02:00
Aleks Hudochenkov a783d6b84d Fix types 2021-05-17 18:23:00 +02:00
Valentin SemirulnikandAndrey Sitnik 6b07218c74 move from source-map to source-map-js 2021-05-17 08:50:13 -04:00
Aleks Hudochenkov 430ee0d902 Add Document node and related API (#1498) 2021-05-16 20:15:56 +02:00
Rouven Weßling 8628ce3a35 Export types for NodeErrorOptions 2021-03-30 12:52:07 +02:00
Niklas Mischkulnig ad88ece3c5 Cleanup: Typescript 2021-01-07 12:33:44 +01:00
Ludovico Fischer cc4714d9d9 Change plugin creator type to allow returning a processor. 2020-12-09 21:06:28 +01:00
Andrey Sitnik 4f8122e557 Clean up fromJSON 2020-12-05 19:36:10 -05:00
Niklas Mischkulnig 781e433bdb Add missing test, linting, typings 2020-12-05 11:07:00 +01:00
Niklas Mischkulnig ec69e352d9 fromJSON and toJSON 2020-12-05 00:15:24 +01:00
Evan YouandGitHub fcbcbe6054 Expose LazyResult type 2020-11-22 15:36:20 -05:00
Arthur PetrieandGitHub 509e641a60 Add missing "comment" export in types + restructure (#1448) 2020-10-23 19:52:33 -04:00
Andrey Sitnik 0d49399d5d Add Once and OnceExit events 2020-09-25 15:56:19 -04:00
Andrey Sitnik c20d10df29 Fix visiting parent on nested children changes 2020-09-23 18:47:27 -04:00
Andrey Sitnik 605a045492 Add Processors docs 2020-09-23 17:54:07 -04:00
Andrey Sitnik 62bfcf38f1 Call RootExit on node changes and Exit only once 2020-09-23 17:36:34 -04:00
Pierre-Marie DartusandGitHub 134e4a0ce2 Add missing Transformer type to processor.d.ts (#1423) 2020-09-23 11:51:20 -04:00
Andrey Sitnik 7a631dc459 Add helpers.postcss 2020-08-24 17:30:01 -05:00
Andrey Sitnik c6d2ab1604 Use RootExit instead of Exit 2020-08-24 00:50:22 -05:00
Andrey Sitnik ff1541c36d Add Exit visitor 2020-08-23 18:26:46 -05:00
Andrey Sitnik ddacc34852 Add Plugin#prepare() 2020-08-22 15:34:57 -05:00
Andrey Sitnik 6a0b8cd0cb Update plugin API in TypeDoc 2020-08-22 00:09:47 -05:00
Andrey Sitnik 4378401239 Add fast filters for decl props and at-rule names 2020-08-10 22:39:24 -07:00
Andrey Sitnik a1e95b2eb3 Clean up code 2020-08-10 22:09:59 -07:00
Andrey Sitnik 0feaad71d5 Fix postcss.Classes type 2020-08-07 13:26:34 -07:00
Andrey Sitnik a539418f45 Use class names in visitor hooks 2020-08-07 12:04:54 -07:00
Andrey Sitnik 15a248c06d Pass postcss & Result to second argument for visitors 2020-08-07 11:46:58 -07:00
Andrey Sitnik 6fbb0d5434 Change plugin API 2020-08-06 16:00:46 -07:00
Andrey Sitnik 9fd442b941 Export TransformCallback 2020-08-05 16:27:09 -07:00
Andrey Sitnik 6de8e0d706 Add opts.map.absolute 2020-07-20 12:36:30 -07:00
Andrey Sitnik 95cc565a13 Fix types for API website 2020-07-15 23:45:38 -07:00