8000 allow TS files to be compiled in src dir by jdeniau · Pull Request #2054 · immutable-js/immutable-js · GitHub
[go: up one dir, main page]

Skip to content

allow TS files to be compiled in src dir #2054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/output_diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ jobs:
working-directory: main

- name: 'Execute prettier and remove ts-expect-error on PR dist'
run: sed '/@ts-expect-error/d' dist/immutable.es.js | npx prettier --parser=babel > dist/immutable.es.prettier.js
run: npx terser dist/immutable.es.js --comments false | npx prettier --parser=babel > dist/immutable.es.prettier.js

working-directory: pr

- name: 'Execute prettier main dist'
run: sed '/@ts-expect-error/d' dist/immutable.es.js | npx prettier --parser=babel > dist/immutable.es.prettier.js
run: npx terser dist/immutable.es.js --comments false | npx prettier --parser=babel > dist/immutable.es.prettier.js
working-directory: main

- name: 'Output diff'
Expand Down
6 changes: 2 additions & 4 deletions __tests__/MultiRequire.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// eslint-disable-next-line @typescript-eslint/no-require-imports, no-undef
const Immutable1 = require('../src/Immutable');
import * as Immutable1 from '../src/Immutable';

jest.resetModules();

// eslint-disable-next-line @typescript-eslint/no-require-imports, no-undef
const Immutable2 = require('../src/Immutable');
const Immutable2 = jest.requireActual('../src/Immutable');

describe('MultiRequire', () => {
it('might require two different instances of Immutable', () => {
Expand Down
9 changes: 1 addition & 8 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default tseslint.config(
{ languageOptions: { globals: globals.browser } },
pluginJs.configs.recommended,
importPlugin.flatConfigs.recommended,
importPlugin.flatConfigs.typescript,
...tseslint.configs.recommended,

{
Expand Down Expand Up @@ -48,14 +49,6 @@ export default tseslint.config(
},
},

{
files: ['**/*.{ts,tsx}'],
extends: [
importPlugin.flatConfigs.recommended,
importPlugin.flatConfigs.typescript,
],
},

{
files: ['src/*'],
rules: {
Expand Down
39 changes: 39 additions & 0 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"lint:format": "prettier --check \"{__tests__,src,type-definitions,website/src,perf,resources}/**/*{.js,.mjs,.ts,.tsx,.flow,.css}\"",
"lint:js": "eslint",
"type-check": "run-s type-check:*",
"type-check:ts": "tsc --project type-definitions/tsconfig.json && tsc --project __tests__/tsconfig.json",
"type-check:ts": "tsc --project tsconfig.src.json && tsc --project type-definitions/tsconfig.json && tsc --project __tests__/tsconfig.json",
"type-check:flow": "flow check type-definitions/flow-tests --include-warnings",
"build": "run-s build:*",
"build:clean": "rimraf dist",
Expand All @@ -87,6 +87,7 @@
"@rollup/plugin-commonjs": "28.0.2",
"@rollup/plugin-json": "6.1.0",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.2",
"@size-limit/esbuild-why": "^8.2.6",
"@size-limit/preset-small-lib": "^8.2.6",
"@types/jest": "^29.0.0",
Expand Down Expand Up @@ -121,6 +122,7 @@
"rollup": "4.34.8",
"size-limit": "^8.2.6",
"transducers-js": "0.4.174",
"tslib": "^2.8.1",
"tstyche": "^3.5",
"typescript": "5.7",
"typescript-eslint": "^8.24.0"
Expand Down
8 changes: 2 additions & 6 deletions resources/jestPreprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ function transpileJavaScript(src, path) {
const buble = require('@rollup/plugin-buble');
const commonjs = require('@rollup/plugin-commonjs');
const json = require('@rollup/plugin-json');
const typescript = require('@rollup/plugin-typescript');

// same input options as in rollup-config.js
const inputOptions = {
input: path,
onwarn: () => {},
plugins: [commonjs(), json(), buble()],
plugins: [commonjs(), json(), typescript(), buble()],
};

const bundle = await rollup.rollup(inputOptions);
Expand Down Expand Up @@ -56,11 +57,6 @@ function transpileJavaScript(src, path) {

module.exports = {
process(src, path) {
if (path.endsWith('__tests__/MultiRequire.js')) {
// exit early for multi-require as we explicitly want to have several instances
return { code: src };
}

if (path.endsWith('.ts') || path.endsWith('.tsx')) {
return { code: transpileTypeScript(src, path) };
}
Expand Down
4 changes: 3 additions & 1 deletion resources/rollup-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import buble from '@rollup/plugin-buble';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import terser from '@rollup/plugin-terser';
// TODO replace @rollup/plugin-typescript with babel after babel migration
import typescript from '@rollup/plugin-typescript';
import copyright from './copyright.mjs';

const SRC_DIR = path.resolve('src');
Expand All @@ -11,7 +13,7 @@ const DIST_DIR = path.resolve('dist');
export default [
{
input: path.join(SRC_DIR, 'Immutable.js'),
plugins: [commonjs(), json(), buble()],
plugins: [commonjs(), json(), typescript(), buble()],
output: [
// umd build
{
Expand Down
2 changes: 1 addition & 1 deletion src/is.js → src/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import { isValueObject } from './predicates/isValueObject';
* All Immutable collections are Value Objects: they implement `equals()`
* and `hashCode()`.
*/
export function is(valueA, valueB) {
export function is(valueA: unknown, valueB: unknown): boolean {
if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
return true;
}
Expand Down
6 changes: 0 additions & 6 deletions src/predicates/isAssociative.js

This file was deleted.

25 changes: 25 additions & 0 deletions src/predicates/isAssociative.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { isKeyed } from './isKeyed';
import { isIndexed } from './isIndexed';
import type { Collection } from '../../type-definitions/immutable';

/**
* True if `maybeAssociative` is either a Keyed or Indexed Collection.
*
* ```js
* import { isAssociative, Map, List, Stack, Set } from 'immutable';
*
* isAssociative([]); // false
* isAssociative({}); // false
* isAssociative(Map()); // true
* isAssociative(List()); // true
* isAssociative(Stack()); // true
* isAssociative(Set()); // false
* ```
*/
export function isAssociative(
maybeAssociative: unknown
): maybeAssociative is
| Collection.Keyed<unknown, unknown>
| Collection.Indexed<unknown> {
return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
}
6 changes: 0 additions & 6 deletions src/predicates/isCollection.js

This file was deleted.

27 changes: 27 additions & 0 deletions src/predicates/isCollection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { Collection } from '../../type-definitions/immutable';

// Note: value is unchanged to not break immutable-devtools.
export const IS_COLLECTION_SYMBOL = '@@__IMMUTABLE_ITERABLE__@@';

/**
* True if `maybeCollection` is a Collection, or any of its subclasses.
*
* ```js
* import { isCollection, Map, List, Stack } from 'immutable';
*
* isCollection([]); // false
* isCollection({}); // false
* isCollection(Map()); // true
* isCollection(List()); // true
* isCollection(Stack()); // true
* ```
*/
export function isCollection(
maybeCollection: unknown
): maybeCollection is Collection<unknown, unknown> {
return Boolean(
maybeCollection &&
// @ts-expect-error: maybeCollection is typed as `{}`, need to change in 6.0 to `maybeCollection && typeof maybeCollection === 'object' && IS_COLLECTION_SYMBOL in maybeCollection`
maybeCollection[IS_COLLECTION_SYMBOL]
);
}
6 changes: 0 additions & 6 deletions src/predicates/isImmutable.js

This file was deleted.

24 changes: 24 additions & 0 deletions src/predicates/isImmutable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Collection, Record } from '../../type-definitions/immutable';
import { isCollection } from './isCollection';
import { isRecord } from './isRecord';

/**
* True if `maybeImmutable` is an Immutable Collection or Record.
*
* Note: Still returns true even if the collections is within a `withMutations()`.
*
* ```js
* import { isImmutable, Map, List, Stack } from 'immutable';
* isImmutable([]); // false
* isImmutable({}); // false
* isImmutable(Map()); // true
* isImmutable(List()); // true
* isImmutable(Stack()); // true
* isImmutable(Map().asMutable()); // true
* ```
*/
export function isImmutable(
maybeImmutable: unknown
): maybeImmutable is Collection<unknown, unknown> | Record<object> {
return isCollection(maybeImmutable) || isRecord(maybeImmutable);
}
5 changes: 0 additions & 5 deletions src/predicates/isIndexed.js

This file was deleted.

27 changes: 27 additions & 0 deletions src/predicates/isIndexed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { Collection } from '../../type-definitions/immutable';

export const IS_INDEXED_SYMBOL = '@@__IMMUTABLE_INDEXED__@@';

/**
* True if `maybeIndexed` is a Collection.Indexed, or any of its subclasses.
*
* ```js
* import { isIndexed, Map, List, Stack, Set } from 'immutable';
*
* isIndexed([]); // false
* isIndexed({}); // false
* isIndexed(Map()); // false
* isIndexed(List()); // true
* isIndexed(Stack()); // true
* isIndexed(Set()); // false
* ```
*/
export function isIndexed(
maybeIndexed: unknown
): maybeIndexed is Collection.Indexed<unknown> {
return Boolean(
maybeIndexed &&
// @ts-expect-error: maybeIndexed is typed as `{}`, need to change in 6.0 to `maybeIndexed && typeof maybeIndexed === 'object' && IS_INDEXED_SYMBOL in maybeIndexed`
maybeIndexed[IS_INDEXED_SYMBOL]
);
}
5 changes: 0 additions & 5 deletions src/predicates/isKeyed.js

This file was deleted.

26 changes: 26 additions & 0 deletions src/predicates/isKeyed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { Collection } from '../../type-definitions/immutable';

export const IS_KEYED_SYMBOL = '@@__IMMUTABLE_KEYED__@@';

/**
* True if `maybeKeyed` is a Collection.Keyed, or any of its subclasses.
*
* ```js
* import { isKeyed, Map, List, Stack } from 'immutable';
*
* isKeyed([]); // false
* isKeyed({}); // false
* isKeyed(Map()); // true
* isKeyed(List()); // false
* isKeyed(Stack()); // false
* ```
*/
export function isKeyed(
maybeKeyed: unknown
): maybeKeyed is Collection.Keyed<unknown, unknown> {
return Boolean(
maybeKeyed &&
// @ts-expect-error: maybeKeyed is typed as `{}`, need to change in 6.0 to `maybeKeyed && typeof maybeKeyed === 'object' && IS_KEYED_SYMBOL in maybeKeyed`
maybeKeyed[IS_KEYED_SYMBOL]
);
}
5 changes: 0 additions & 5 deletions src/predicates/isList.js

This file was deleted.

14 changes: 14 additions & 0 deletions src/predicates/isList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { List } from '../../type-definitions/immutable';

export const IS_LIST_SYMBOL = '@@__IMMUTABLE_LIST__@@';

/**
* True if `maybeList` is a List.
*/
export function isList(maybeList: unknown): maybeList is List<unknown> {
return Boolean(
maybeList &&
// @ts-expect-error: maybeList is typed as `{}`, need to change in 6.0 to `maybeList && typeof maybeList === 'object' && IS_LIST_SYMBOL in maybeList`
maybeList[IS_LIST_SYMBOL]
);
}
5 changes: 0 additions & 5 deletions src/predicates/isMap.js

This file was deleted.

Loading
0