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

gh-75 fixing babel cache issue #288

Merged
merged 11 commits into from Mar 17, 2022
Merged

gh-75 fixing babel cache issue #288

merged 11 commits into from Mar 17, 2022

Conversation

goatandsheep
Copy link
Owner

@goatandsheep goatandsheep commented Feb 7, 2022

Link to issue

fixes #75

Description of changes being made

  • refactor to work with new babel version

@goatandsheep
Copy link
Owner Author

This will duplicate functionality so closes #290

@codecov
Copy link

codecov bot commented Feb 14, 2022

Codecov Report

Merging #288 (5bd695a) into main (e68997c) will increase coverage by 0.76%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #288      +/-   ##
==========================================
+ Coverage   98.21%   98.97%   +0.76%     
==========================================
  Files           1        1              
  Lines          56       98      +42     
==========================================
+ Hits           55       97      +42     
  Misses          1        1              
Impacted Files Coverage Δ
index.js 98.97% <100.00%> (+0.76%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e68997c...5bd695a. Read the comment docs.

verbose: false,
...options,
}
const babelMode = process.env[options.envName] || (process.env.BABEL_ENV && process.env.BABEL_ENV !== 'undefined' && process.env.BABEL_ENV !== 'development' && process.env.BABEL_ENV) || process.env.NODE_ENV || 'development'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to wrap this in cache.using, so that if the env changes without restarting Node.js the plugin is reinstantiated.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you! I moved things around. I still don't know if it will reload properly in hot reload, but I don't think the environment mode can change without a js reload so I left that out. Hopefully it works in other tests when we release it in @next!

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am the second maintainer to this project so I'm not even sure about how all the babel features work

@goatandsheep goatandsheep changed the title [Draft] experimenting with new babel feature [Draft] fixing babel cache issue Feb 15, 2022
index.js Outdated
console.log('dotenvMode', babelMode)
}

api.cache.using(() => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function passed to api.cache.using should return a value that, when it changes, causes the plugin to be re-instantiated. Since this one always returns undefined, the plugin will never be re-instantiated and it will always use the initial .env file.

I suggest doing something like this:

function mtime(filePath) {
  try {
    return fs.statSync(filePath).mtimeMs
  } catch {
    return null
  }
}

api.cache.using(() => mtime(options.path))
api.cache.using(() => mtime(localFilePath))
api.cache.using(() => mtime(modeFilePath))
api.cache.using(() => mtime(modeLocalFilePath))

let env

if (options.safe) {
  const parsed = parseDotenvFile(options.path, options.verbose)
  const localParsed = parseDotenvFile(localFilePath, options.verbose)
  const modeParsed = parseDotenvFile(modeFilePath, options.verbose)
  const modeLocalParsed = parseDotenvFile(modeLocalFilePath, options.verbose)
  
  env = Object.assign(Object.assign(Object.assign(parsed, modeParsed), localParsed), modeLocalParsed)
} else {
  dotenv.config({
    path: modeLocalFilePath,
    silent: true,
  })
  dotenv.config({
    path: modeFilePath,
    silent: true,
  })
  dotenv.config({
    path: localFilePath,
    silent: true,
  })
  dotenv.config({
    path: options.path,
  })
      
  env = process.env
}

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so when it is re-initialized, pre() is rerun?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so I found that this did not work in tests unfortunately. do I also need to use addExternalDependency?

@goatandsheep
Copy link
Owner Author

goatandsheep commented Mar 16, 2022

Codecoverage issue

targetObject[keys[i]] = sourceObject[keys[i]]
  | 26

Uploading Screen Shot 2022-03-16 at 7.47.07 PM.png…

@goatandsheep goatandsheep changed the title [Draft] fixing babel cache issue fixing babel cache issue Mar 17, 2022
@goatandsheep goatandsheep changed the title fixing babel cache issue gh-75 fixing babel cache issue Mar 17, 2022
@goatandsheep goatandsheep merged commit 4684b5e into main Mar 17, 2022
@goatandsheep goatandsheep deleted the bugfix/gh-75 branch March 17, 2022 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.env file variables are cached
2 participants