36 Commits
Author SHA1 Message Date
Andrey Sitnik d3d4d735df Update ESLint config 2025-02-19 13:43:47 +00:00
Andrey Sitnik 89b7f7ac78 Update dependencies and code style 2023-07-06 13:38:48 +02:00
Remco Haszing f1684ebfa6 Revert tests 2023-03-26 13:51:56 +02:00
Remco Haszing 4ffffca221 Add hacks needed to make check-dts work 2023-03-02 12:40:37 +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
Vitaly Turovsky cd0a159592 fix tests 2022-05-13 17:39:56 +03:00
Andrey Sitnik 02ac5b3770 Throws error on NoWorkResult.root access 2022-01-31 00:43:45 +01:00
Andrey Sitnik 94a06fcf34 Clean up tests 2021-11-26 19:21:39 +01:00
Andrey Sitnik 7991e0677b Clean up tests 2021-11-26 14:31:34 +01:00
Andrey Kim afe45db6e8 Merge branch 'main' of https://github.com/postcss/postcss into main 2021-11-17 23:55:23 +03:00
Andrey Kim cd9ec4f200 Move from Jest to uvu 2021-11-15 11:25:34 +03:00
Bogdan Dolin 207e5c9b2a add expect for 100% coverage 2021-11-08 13:49:20 +07:00
Bogdan Dolin 39968b4c29 rewrite catch error test 2021-11-07 12:02:39 +07:00
5fb9c4cc32 Update test/processor.test.ts
Co-authored-by: Andrey Sitnik <[email protected]>
2021-11-06 10:22:08 +07:00
bogdan0083 66c2a84b25 Fix tests 2021-11-05 11:32:12 +07:00
bogdan0083 f8b471807a Add tests 2021-11-05 11:14:36 +07:00
WilhelmYakunin 9055df53c6 add no-work in case of no options made 2021-10-27 23:34:47 +03:00
Andrey Sitnik 6176e9ec7a Update dependencies 2021-10-20 17:11:51 +02:00
Andrey Sitnik 735880a8d8 Fix types 2021-09-22 08:02:22 +02:00
Andrey Sitnik 14a54d0525 Better useless PostCSS run test 2021-06-09 19:35:44 -04:00
Andrey Sitnik 279d287dea Use codeBefore instead of markupBefore 2021-05-18 20:50:45 -04:00
Aleks Hudochenkov eeea51219e Fix Parser type 2021-05-18 23:48:26 +02:00
Aleks Hudochenkov 205f9a9063 Test custom parser 2021-05-18 23:41:23 +02:00
Andrey Sitnik 7c959ea4e8 Clean up tests 2021-04-26 08:23:50 -04:00
Andrey Sitnik 843ab11b6e Add Prettier 2021-03-11 19:11:37 -05:00
Andrey Sitnik 839e2c0504 Update ESLint config 2021-03-09 17:02:16 -05:00
Andrey Sitnik 6208bd61b6 Clean up tests 2020-12-29 14:35:30 -05:00
Ludovico Fischer cc4714d9d9 Change plugin creator type to allow returning a processor. 2020-12-09 21:06:28 +01:00
Andrey Sitnik fe4b7310a9 Update dependencies 2020-11-21 13:29:30 -05:00
Oscar OteroandGitHub 4357171f9d Code style changes to Deno port (#1432)
* code style changes to port to Deno

* import only the used functions from 'path'
2020-10-01 19:29:25 -04:00
Andrey Sitnik 0d49399d5d Add Once and OnceExit events 2020-09-25 15:56:19 -04:00
Andrey Sitnik 8cd8802817 Fix plugin packs support 2020-09-15 12:44:40 -04:00
Andrey Sitnik 887783b405 Change plugin running code and mark moved nodes as dirty 2020-09-05 00:31:30 -04:00
Andrey Sitnik 6fbb0d5434 Change plugin API 2020-08-06 16:00:46 -07:00
Andrey Sitnik 389b7b00a9 Export public classes from main entry 2020-07-12 16:31:09 -07:00
Andrey Sitnik 1ba2f7afc6 Move Processor test to TS 2020-07-09 22:56:35 -07:00