26 Commits

Author SHA1 Message Date
Anton Gilgur
b44b069cb2
fix: force noEmitOnError: false (#338)
- `noEmitOnError: true` acts like `noEmit: true` when there is an error
  - this is problematic because it will then cause _all_ files to have
    `emitSkipped` set to `true`, which this plugin interprets as a fatal
    error
    - meaning it will treat the first file it finds as having a fatal
      error and then abort, but possibly without outputting any
      diagnostics what-so-ever as the file with the error in it may not
      yet have run through the `transform` hook
      - i.e. an initial file that imports an erroring file at some point
        in its import chain will cause rpt2 to abort, even if that
        initial file _itself_ has no type-check/diagnostic issues
        - bc TS does whole-program analysis after all

- this has only been reported as an issue once so far, probably because
  it defaults to `false` in TS and, as such, is rarely used:
  https://www.typescriptlang.org/tsconfig#noEmitOnError
  - we usually have the opposite issue, people trying to set it to
    `false` (i.e. the default) because they don't realize the
    `abortOnError` option exists

- add `noEmitOnError: false` to the forced options list and tests too

- add it to the docs on what tsconfig options are forced
  - and add a reference to the issue like the existing options
  - also reference `abortOnError` since they're commonly associated with
    each other and that plugin option is often missed (per above)
- briefly explain that `noEmit` and `noEmitOnError` are `false` because
  Rollup controls emit settings in the context of this plugin, instead
  of `tsc` etc
  - should probably watch out for when new emit settings are added to
    TS, as we may want to force most with the same reasoning
2022-06-01 14:42:46 -06:00
Anton Gilgur
b08f272efb
refactor: sort all top-level imports (#337)
- basically, general format is:
  ```ts
  import x from "external-dep"

  import y from "./internal-dep"
  ```
  - so external deps, new line, then internal/local deps
  - with some further sorting within there, like trying to keep Node
    built-ins (e.g. `path`) at the top half of externals, then core deps
    like `typescript`, then any other external deps
    - and similar for internal deps -- core internals at the top half of
      internals, then any other internal deps
    - just to keep things consistent between files -- makes the top
      easier to read through when it's similar between files
    - also makes it easier for contributors to understand where to put
      imports, as there's a sorting already there

- this is how I generally sort my imports and how I wrote most of the
  unit test suite's imports as well

- there is automation for this that we should probably add once TSLint
  is replaced here; some previous art:
  - https://github.com/trivago/prettier-plugin-sort-imports
  - https://github.com/lydell/eslint-plugin-simple-import-sort/
  - Older:
    - https://github.com/renke/import-sort/tree/master/packages/import-sort-style-module
    - https://github.com/mcdougal/js-isort
    - inspired by Python's `isort` ofc
2022-06-01 14:40:54 -06:00
Anton Gilgur
d318e9a8fc
fix: normalize paths in get-options-overrides (#331)
- the `outDir` was not normalized after the `/placeholder` part was
  added to `cacheRoot`
  - `cacheRoot` could have `\` directory separators on it on Windows,
    which caused some tests to fail on Windows before
  - tests have been normalized now too

- `expandIncludeWithDirs` used `path.join` without normalizing after
  - `path.join` uses the OS's native separators (`posix.join` would do
    POSIX separators only), so when the paths were already normalized
    and then `path.join`ed, this would cause mixed separators on Windows
  - this fixes the current CI failure on Windows in the `createFilter`
    tests (`rootDirs` and `projectReferences`, which use
    `expandIncludeWithDirs`)
    - c.f. https://github.com/ezolenko/rollup-plugin-typescript2/runs/6516149780?check_suite_focus=true
2022-05-30 10:09:00 -06:00
Anton Gilgur
197061bf92
refactor: prefer native methods to lodash where possible (#328)
- _.endsWith -> String.endsWith

- _.concat -> Array.concat
- _.each -> Array.forEach
- _.filter -> Array.filter
- _.map -> Array.map
- _.some -> Array.some

- _.has -> `key in Object`
- _.defaults -> Object.assign
- _.get -> `?.` and `??` (optional chaining and nullish coalescing)

- refactor: replace fairly complicated `expandIncludeWithDirs` func to
  just use a few simple `forEach`s
  - not as FP anymore, more imperative, but much simpler to read IMO
- refactor: add a `getDiagnostics` helper to DRY up some code
  - also aids readability IMO

- a few places are still using lodash, but this paves the way toward
  removing it or replacing it with much smaller individual deps
  - _.compact still used because Array.filter heavily complicates the
    type-checking currently
  - _.isFunction still used because while it's a one-liner natively,
    need to import a function in several places
    - also the package `lodash.isFunction` is lodash v3 and quite
      different from the v4 implementation, so couldn't replace with it
      unfortunately
  - _.merge is a deep merge, so there's no native version of this
    - but we may remove deep merges entirely in the future (as tsconfig
      doesn't quite perform a deep merge), or could replace this with a
      smaller `lodash.merge` package or similar

- see also https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore
2022-05-16 16:30:48 -06:00
Nicolas THIERION
e9af09fe0f
fix: use compilerOptions.rootDir to filter files (#249)
When compilerOptions.rootDir is specified, it is used instead of process.cwd() to filter files. 

Possible fix for #237
2020-10-29 09:41:12 -06:00
Anton Gilgur
ec0568ba2c (fix): declaration maps should have correct sources
- previously, declarationDir was set to cwd if useTsconfigDeclarationDir
  wasn't true, however, declarations aren't output to cwd, but to
  Rollup's output destination, so this was incorrect
  - instead, don't set declarationDir, which defaults it to outDir,
    which is currently set to a placeholder
    - previously, it rewrote declarations to output to Rollup's dest
      from cwd, now rewrite from outDir placeholder instead
  - and add a rewrite of sources to match relative path from Rollup's
    output dest instead of outDir placeholder

- also change the one line in the docs that says it'll be
  `process.cwd()`; every other reference says it'll be the output dest
2020-09-30 19:46:37 -04:00
Tiger Oakes
c6c733fcb5 Use imports with @rollup/pluginutils 2020-03-26 11:07:35 -07:00
chencheng (云谦)
4217346054 feat: support options.cwd (#197) 2019-12-03 10:20:41 -07:00
Eugene Zolenko
f4ee39c979 - partial support for project references #139 2019-02-25 14:33:04 -07:00
Eugene Zolenko
9188132749 - refactoring 2019-02-25 11:18:48 -07:00
Eugene Zolenko
d1082d830f - fix for #131 2019-01-15 18:15:43 -07:00
Eugene Zolenko
3a6079c1ec - using allowNonTsExtensions to let other plugins generate typescript #111 2018-10-30 10:23:22 -06:00
Eugene Zolenko
95ed8869cf - fix for extended tsconfigs #101 2018-09-25 11:40:27 -06:00
Eugene Zolenko
1986879fdb - unsetting sourceRoot when inlineSourceMap gets overriden, fix for #99 2018-07-13 14:43:31 -06:00
Eugene Zolenko
d289d3f725 - outDir placeholder other than cwd, fix for #83 2018-06-06 14:51:23 -06:00
ezolenko
6b41d6758f - #71 forcing inlineSourceMap to false 2018-04-13 23:31:25 -06:00
ezolenko
7332077918 - relaxing module overrides to allow for ESNext #54 2018-03-06 18:34:12 -07:00
Eugene Zolenko
e6e72fb2b0 - fix for #52 2018-01-29 12:04:31 -07:00
Eugene Zolenko
8f17a0a120 - changing noEmitHelpers override to false (#48) 2018-01-10 10:35:01 -07:00
frankwallis
d4f283ee00 override noEmit option to false when set (#44) 2017-11-23 15:47:18 -07:00
Eugene Zolenko
fa1bbf8882 - partial tsconfig override from plugin options (#33) 2017-09-27 17:31:18 -06:00
ezolenko
448913d411 - fix for #24. forcing declarations for project files even if they are ignored by rollup 2017-08-15 17:56:29 -06:00
ezolenko
81228203cf - option for overriding typescript version for #27 2017-08-11 00:33:36 -06:00
ezolenko
c501e1a34f - fix for TS5052
- cleanup
2017-07-31 23:27:05 -06:00
wessberg
a6f75b4f11 Added options to respect declarationDir from tsconfig 2017-07-31 15:14:50 +02:00
wessberg
29eae41e26 Refactoring. Declarations will now be local to the rollup destination directory 2017-07-27 04:22:49 +02:00