nix-community / nixt

Simple unit-testing for Nix [maintainer=@Lord-Valen]
MIT License
104 stars 11 forks source link

Investigate inconsistency between `nix build` and `nix develop` #10

Closed Lord-Valen closed 2 years ago

Lord-Valen commented 2 years ago

Currently nix build works as intended, it runs the preinstall script without issue and outputs nixt in result/bin. Nix develop fails to build. It appears that tsc is not running with the correct working directory, causing tsc to print its help screen instead of transpiling. If the shell node2nix provides is meant for dev use then npm install probably shouldn't be running at all. If it's meant to be run, npm install should return the same result as it does when building. I may have to roll my own devShell.

> nixt@0.2.1 preinstall /nix/store/9230zmgs46fpc1ggw68d0485ax44cikz-node>
> npm run build

> nixt@0.2.1 build /nix/store/yw2xs0sw9bpyi3gm92w1qachw3wxa0s9-node-dependencies-nixt-0.2.1/nixt
> tsc

Version 4.7.4
tsc: The TypeScript Compiler - Version 4.7.4

COMMON COMMANDS

  tsc
  Compiles the current project (tsconfig.json in the working directory.)

  tsc app.ts util.ts
  Ignoring tsconfig.json, compiles the specified files with default compiler options.

  tsc -b
  Build a composite project in the working directory.

  tsc --init
  Creates a tsconfig.json with the recommended settings in the working directory.

  tsc -p ./path/to/tsconfig.json
  Compiles the TypeScript project located at the specified path.

  tsc --help --all
  An expanded version of this information, showing all possible compiler options

  tsc --noEmit
  tsc --target esnext
  Compiles the current project, with additional settings.

COMMAND LINE FLAGS

--help, -h
Print this message.

--watch, -w
Watch input files.

--all
Show all compiler options.

--version, -v
Print the compiler's version.

--init
Initializes a TypeScript project and creates a tsconfig.json file.

--project, -p
Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'.

--build, -b
Build one or more projects and their dependencies, if out of date

--showConfig
Print the final configuration instead of building.

COMMON COMPILER OPTIONS

--pretty
Enable color and formatting in TypeScript's output to make compiler errors easier to read.
type: boolean
default: true

--target, -t
Set the JavaScript language version for emitted JavaScript and include compatible library declarations.
one of: es3, es5, es6/es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022, esnext
default: es3

--module, -m
Specify what module code is generated.
one of: none, commonjs, amd, umd, system, es6/es2015, es2020, es2022, esnext, node16, nodenext
default: undefined

--lib
Specify a set of bundled library declaration files that describe the target runtime environment.
one or more: es5, es6/es2015, es7/es2016, es2017, es2018, es2019, es2020, es2021, es2022, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable/esnext.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol/esnext.symbol, es2020.bigint/esnext.bigint, es2020.date, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2020.number, es2021.promise/esnext.promise, es2021.string, es2021.weakref/esnext.weakref, es2021.intl, es2022.array/esnext.array, es2022.error, es2022.intl, es2022.object, es2022.string/esnext.string, esnext.intl
default: undefined

--allowJs
Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files.
type: boolean
default: false

--checkJs
Enable error reporting in type-checked JavaScript files.
type: boolean
default: false

--jsx
Specify what JSX code is generated.
one of: preserve, react, react-native, react-jsx, react-jsxdev
default: undefined

--declaration, -d
Generate .d.ts files from TypeScript and JavaScript files in your project.
type: boolean
default: `false`, unless `composite` is set

--declarationMap
Create sourcemaps for d.ts files.
type: boolean
default: false

--emitDeclarationOnly
Only output d.ts files and not JavaScript files.
type: boolean
default: false

--sourceMap
Create source map files for emitted JavaScript files.
type: boolean
default: false

--outFile
Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output.

--outDir
Specify an output folder for all emitted files.

--removeComments
Disable emitting comments.
type: boolean
default: false

--noEmit
Disable emitting files from a compilation.
type: boolean
default: false

--strict
Enable all strict type-checking options.
type: boolean
default: false

--types
Specify type package names to be included without being referenced in a source file.

--esModuleInterop
Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility.
type: boolean
default: false

You can learn about all of the compiler options at https://aka.ms/tsc

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nixt@0.2.1 build: `tsc`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the nixt@0.2.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /build/.npm/_logs/2022-07-19T23_32_19_956Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nixt@0.2.1 preinstall: `npm run build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the nixt@0.2.1 preinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /build/.npm/_logs/2022-07-19T23_32_20_182Z-debug.log

error: builder for '/nix/store/aly55j3zr5s2vhzqj2yc535rywf1hb5v-node-dependencies-nixt-0.2.1.drv' failed with exit code 1;
       last 10 log lines:
       > npm ERR! errno 1
       > npm ERR! nixt@0.2.1 preinstall: `npm run build`
       > npm ERR! Exit status 1
       > npm ERR!
       > npm ERR! Failed at the nixt@0.2.1 preinstall script.
       > npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
       > 
       > npm ERR! A complete log of this run can be found in:
       > npm ERR!     /build/.npm/_logs/2022-07-19T23_32_20_182Z-debug.log
Lord-Valen commented 2 years ago

Upon further inspection (I included pwd in the build script), tsc is run in the correct directory; however, tsconfig.json is not present in the nix store.

Lord-Valen commented 2 years ago

The issue was that package.json is shared between the derivations for nixt and the node-dependencies so when the node-dependencies are built, the preinstall script (the build script, by proxy) is run, BUT tsconfig.json and the source tree are not present in that derivation. Worked around this by checking for tsconfig.json in the build script and exiting cleanly if it is missing. This could be an issue as if tsc for any reason throws, the error will be ignored and the script will still return 0.