24 Commits
Author SHA1 Message Date
Andrey Sitnik 85bf516d71 Move to oxfmt 2026-04-07 16:07:54 +00:00
Andrey Sitnik f45d36cfdb Update dependencies 2025-10-18 14:12:14 +00: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
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 69ae8d48ab Fix TSDocs 2023-04-19 21:01:31 +02:00
Remco Haszing 113970af29 Remove intermediate classes for default exports 2023-04-15 13:00:25 +02:00
Remco Haszing f739b0bde1 Use ESM imports in type definitions 2023-03-27 18:45:38 +02:00
Remco Haszing 676fb8a0ae Fix default exports with inheritance 2023-03-27 18:08:45 +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
Andrey Sitnik 89663ccdea Fix TypeDoc 2022-04-09 10:33:38 +02:00
bogdan0083 b8df58d676 Merge remote-tracking branch 'upstream/main' into implement-nowork 2021-11-06 11:47:58 +07:00
Andrey Sitnik 4943de8955 Remove precss 2021-11-05 20:40:52 +01:00
Paul ShryockandGitHub 60b1579c56 Remove unmaintained precss from type definitions 2021-11-05 15:28:06 -04:00
bogdan0083 c43d0387cb Update processor.js 2021-11-05 11:12:04 +07:00
Andrey Sitnik 843ab11b6e Add Prettier 2021-03-11 19:11:37 -05:00
Pierre-Marie DartusandGitHub 134e4a0ce2 Add missing Transformer type to processor.d.ts (#1423) 2020-09-23 11:51:20 -04:00
Andrey Sitnik 6fbb0d5434 Change plugin API 2020-08-06 16:00:46 -07:00
Andrey Sitnik 1ba2f7afc6 Move Processor test to TS 2020-07-09 22:56:35 -07:00
Andrey Sitnik 981b016135 Update imports 2020-07-09 21:11:51 -07:00
Andrey Sitnik 72cea6a6b6 Remove JSDoc links 2020-07-09 18:14:53 -07:00
Andrey Sitnik 8aae507a45 Clean up types and replace JSDoc to TypeDoc 2020-07-08 17:55:13 -07:00