Skip to content
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

v0.9 image fails trying to load schema from current directory #1023

Open
ssube opened this issue Feb 17, 2022 · 2 comments
Open

v0.9 image fails trying to load schema from current directory #1023

ssube opened this issue Feb 17, 2022 · 2 comments

Comments

@ssube
Copy link
Owner

ssube commented Feb 17, 2022

Bug

Something is broken!

Summary

Error loading schema to validate config since v0.9 image was published.

Steps to Reproduce

  • run the docker image with cjs bundle

Actual Behavior

uncaught error during main: Error: ENOENT: no such file or directory, open '/build/src/git.company.com/sKSMtss1/1/x/y/z/rules/salty-dog.yml'
    at Object.openSync (node:fs:585:3)
    at readFileSync (node:fs:453:35)
    at loadSchema (/usr/local/share/.config/yarn/global/node_modules/salty-dog/out/bundle/index.cjs:33664:44)
    at validateConfig (/usr/local/share/.config/yarn/global/node_modules/salty-dog/out/bundle/index.cjs:33687:33)
    at main (/usr/local/share/.config/yarn/global/node_modules/salty-dog/out/bundle/index.cjs:33775:8) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/build/src/git.company.com/sKSMtss1/1/x/y/z/rules/salty-dog.yml'
}

Expected Behavior

Should load the config from /salty-dog/rules/salty-dog.yml (or ../../rules, relative to the entrypoint script), whether that is /salty-dog/out/bundle/index.cjs or /salty-dog/out/src/index.js.

@ssube
Copy link
Owner Author

ssube commented Feb 17, 2022

This is being caused by esbuild, and there is a warning during bundling:

node config/esbuild.mjs
▲ [WARNING] "import.meta" is not available in the configured target environment ("es2017") and will be empty
    out/src/config/index.js:11:18:
      11 │     if (doesExist(import.meta) && doesExist(import.meta.url)) {
         ╵                   ~~~~~~~~~~~
  The target environment was set to "es2017" here:
    config/tsconfig.json:25:14:
      25 │     "target": "es2017",
         ╵               ~~~~~~~~
▲ [WARNING] "import.meta" is not available in the configured target environment ("es2017") and will be empty
    out/src/config/index.js:11:44:
      11 │     if (doesExist(import.meta) && doesExist(import.meta.url)) {
         ╵                                             ~~~~~~~~~~~
  The target environment was set to "es2017" here:
    config/tsconfig.json:25:14:
      25 │     "target": "es2017",
         ╵               ~~~~~~~~
▲ [WARNING] "import.meta" is not available in the configured target environment ("es2017") and will be empty
    out/src/config/index.js:12:42:
      12 │ ...n join(dirname(fileURLToPath(import.meta.url)), '..', '..', '..');
         ╵                                 ~~~~~~~~~~~
  The target environment was set to "es2017" here:
    config/tsconfig.json:25:14:
      25 │     "target": "es2017",
         ╵               ~~~~~~~~

(https://git.apextoaster.com/ssube/salty-dog/-/jobs/385796)

The code falls back to process.cwd():

/**
 * Path to project root directory.
 */
export function dirName(): string {
  if (doesExist(import.meta) && doesExist(import.meta.url)) {
    return join(dirname(fileURLToPath(import.meta.url)), '..', '..', '..');
  } else {
    return process.cwd();
  }
}

(https://github.com/ssube/salty-dog/blob/master/src/config/index.ts#L29)

@ssube ssube closed this as completed in f40a52a Feb 17, 2022
@ssube ssube reopened this Feb 17, 2022
@ssube
Copy link
Owner Author

ssube commented Feb 17, 2022

The first case, running the container itself, is fixed. Running the global command from within the container, is not:

dirName called [
  '/usr/local/bin/node',
  '/usr/local/bin/salty-dog',
  'check',
  '--config-path',
  '/salty-dog/docs'
]
uncaught error during main: Error: ENOENT: no such file or directory, open '/usr/rules/salty-dog.yml'
    at Object.openSync (node:fs:585:3)
    at readFileSync (node:fs:453:35)
    at loadSchema (/usr/local/share/.config/yarn/global/node_modules/salty-dog/out/bundle/index.cjs:33805:44)
    at validateConfig (/usr/local/share/.config/yarn/global/node_modules/salty-dog/out/bundle/index.cjs:33828:33)
    at main (/usr/local/share/.config/yarn/global/node_modules/salty-dog/out/bundle/index.cjs:33916:8) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/usr/rules/salty-dog.yml'
}

The usual logic for finding rules/ does not apply to the /usr/local/bin/salty-dog binary/command path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant