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

refactor: Separate internal concepts of config and env #1734

Merged
merged 2 commits into from
Nov 18, 2022

Conversation

rschristian
Copy link
Member

@rschristian rschristian commented Aug 13, 2022

What kind of change does this PR introduce?

refactor

Did you add tests for your changes?

Existing cover

Summary

In CLI, we mix the concepts of 'configuration' and 'environment' quite heavily; this means mixing together properties like isProd and pkg.dependencies. Accordingly, in different parts of the source, we refer to this mega variable as env or config.

What this PR proposes is to separate these out: app configuration values are separate to environment values.

This came about from a user messaging me about checking env in their preact.config.js and seeing all sorts of values that would never be of any use to them. See below for what console.log(env) results in.

Full `env` object
{
  _: [],
  prerender: false,
  sw: false,
  src: '/home/ryun/Projects/cli/src',
  dest: '/home/ryun/Projects/cli/build',
  cwd: '/home/ryun/Projects/cli',
  babelConfig: '.babelrc',
  json: undefined,
  template: undefined,
  preload: false,
  analyze: undefined,
  prerenderUrls: 'prerender-urls.json',
  brotli: false,
  'inline-css': true,
  config: 'preact.config.js',
  c: 'preact.config.js',
  production: true,
  isProd: true,
  isWatch: false,
  source: [Function (anonymous)],
  manifest: {
    name: 'foo',
    short_name: 'foo',
    start_url: '/',
    display: 'standalone',
    orientation: 'portrait',
    background_color: '#fff',
    theme_color: '#673ab8',
    icons: [ [Object], [Object] ]
  },
  pkg: {
    private: true,
    scripts: {
      build: 'preact build --no-prerender --no-sw',
      'serve:prod': 'sirv build --port 3000 --cors --single',
      'serve:dev': 'preact watch',
      lint: 'eslint src',
      test: 'jest'
    },
    devDependencies: {
      'preact-cli': 'file:.yalc/preact-cli',
      prettier: '^2.7.1',
      'prettier-config-rschristian': '^0.1.1',
      'sirv-cli': '1.0.3'
    },
    dependencies: {
      preact: '^10.3.2',
      'preact-iso': '^2.3.0',
      'preact-render-to-string': '^5.1.4',
      'preact-router': '^3.2.1'
    }
  },
  isServer: false,
  dev: false,
  ssr: false
}

While we could just limit what we return to users, this also creates potential issues in our source. It's difficult to know when and where we set what values as this is treated like a global, just a less convenient one. For example, I went on a bit of a hunt earlier in trying to find out where in the world we set isServer. Hint: it's absolutely no where near where we set isProd or the like.

Additionally, there's an issue of multiple semi-duplicated values: production and isProd, ssr and isServer. While some of these are set together as aliases, others are not, and there's always the potential issue of them not being in sync. We should cut these down into a consistent list of idiomatic conditions for both us and users to use.

Does this PR introduce a breaking change?

Yes, some values from env will be stripped. See changeset for better log.

@changeset-bot
Copy link

changeset-bot bot commented Aug 13, 2022

🦋 Changeset detected

Latest commit: 62caa1f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
preact-cli Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@rschristian rschristian marked this pull request as ready for review November 18, 2022 05:45
@rschristian rschristian requested a review from a team as a code owner November 18, 2022 05:45
@rschristian rschristian merged commit d15d8a6 into next Nov 18, 2022
@rschristian rschristian deleted the refactor/separate-config-env branch November 18, 2022 07:35
rschristian added a commit that referenced this pull request Dec 13, 2022
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Dec 13, 2022
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Dec 13, 2022
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Dec 13, 2022
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Dec 13, 2022
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Dec 13, 2022
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Dec 13, 2022
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Dec 13, 2022
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Dec 18, 2022
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Dec 20, 2022
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Dec 20, 2022
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Dec 20, 2022
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Dec 20, 2022
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Dec 21, 2022
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Dec 22, 2022
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Dec 23, 2022
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Dec 24, 2022
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Dec 24, 2022
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Dec 24, 2022
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Jan 6, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Jan 6, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Jan 6, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Jan 6, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Jan 6, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Jan 7, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Jan 7, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Jan 7, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Jan 8, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Jan 9, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Jan 9, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Jan 9, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Jan 9, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Jan 16, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Jan 31, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Jan 31, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Jan 31, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Jan 31, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Feb 2, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Oct 10, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Oct 10, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Oct 10, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Oct 10, 2023
* refactor: Separate internal concepts of config and env

* docs: Adding changeset
rschristian added a commit that referenced this pull request Oct 10, 2023
* Chore: Updating html-webpack-plugin to v4 (#1608)

* chore: Correcting changeset

* feat: webpack v5 (#1645)

* feat: webpack-v5

* test: Update tests

* docs: Updating docs to reflect changes

* chore: Removing optimize-plugin local patch

* refactor: Determine CSS module by filename, not directory (#1714)

* refactor: Determine CSS module by filename, not directory

* docs: Adding changeset

* refactor: Project creation pull from templates 'main' branch

* test: Updating tests

* revert: Accidentally removed log message

* refactor: Extracting project creation out to own package (#1708)

* refactor: Extracting out project creation to own package

* docs: Adding changeset

* refactor: Misc edits to common deps & workspace helper scripts

* test: Fixing 'create' test suite

* ci: Increase minimum Node version

* chore: Fix typos

* docs: Update ReadMe instructions

* chore: Better (and untaken) package name

* docs: Update changeset

* test: Update 'create' test suite & build output hashes

* docs: Expounding upon changeset

* refactor: Drop Preact 8 support (#1716)

* refactor: Drops support for Preact v8

* docs: Adding changeset

* refactor: Switch to automatic runtime JSX transform (#1725)

* refactor: Switch over to automatic runtime transform for JSX

* test: Removing `h` imports from test suite

* docs: Adding changeset

* docs: Adding readme for create-cli (#1728)

* docs: Adding readme for create-cli

* feat: Initial publish

* fix: Correcting broken readme links

* refactor: Disable hashing ssr-build's css (#1733)

* refactor: Disable hashing ssr-build's css

* docs: Adding changeset

* test: Fix unrelated change from altered template

* refactor: Remove `--preload` flag (#1737)

* refactor: Removes `--preload` flag & functionality

* docs: Adding changeset

* docs: Updating readme for removal of preload

* refactor: Separate internal concepts of config and env (#1734)

* refactor: Separate internal concepts of config and env

* docs: Adding changeset

* refactor: prune flags (#1752)

* refactor: Revise inconsistent, unused, and deprecated flags

* docs: Adding changeset

* feat: Improved errors and warnings (#1758)

* refactor: Better root error handling

* refactor: Switch prerender plugin to be async for error gen

* refactor: Simplify & improve compilation messages

* refactor: Bump Node version, remove `src` arg in build & watch, and misc housekeeping (#1753)

* refactor: Drop rimraf for built-in fs.rm

* refactor: Drop src argument in build & watch cmds

* refactor: Extract info cmd from CLI entrypoint

* refactor: Remove update-notifier

* refactor: Switch from fs.promises to fs/promises

* docs: Adding changeset

* refactor: Move EJS into user templates (`template.html`) (#1768)

* refactor: Merging EJS templates and switcing preferred template extension to .ejs

* test: Fixing test suite to reflect latest changes

* chore: Cleaning

* docs: Updating ReadMe

* docs: Adding changeset

* refactor: Add error message for <% preact.(head|body)End %>

* chore: Publishing cli & create-cli

* Refactor: Enable Prefresh by Default (#1772)

* refactor: Enables HMR via Prefresh by default

* docs: Adding changeset

* test: Updating tests to reflect changes to templates

* refactor: Remove Critters (perhaps temporarily) (#1778)

* refactor: Remove Critters (perhaps temporarily)

* docs: Adding changeset

* chore: Publish v4.0.0-next.2

* refactor: Vendor Critters so that 7c811ac can be reverted (#1780)

* docs: Remove CLI beta note from readme

* docs: Bump minimum Node version listed in readme
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.

None yet

1 participant