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

Update Parcel to a stable release #399

Closed
thewilkybarkid opened this issue Aug 20, 2021 · 11 comments
Closed

Update Parcel to a stable release #399

thewilkybarkid opened this issue Aug 20, 2021 · 11 comments

Comments

@thewilkybarkid
Copy link
Member

Parcel has had its first release candidate released; this includes changes such as changing the JavaScript compiler (actually in beta 3).

After an initial test, the project as-in doesn't build.

thewilkybarkid added a commit that referenced this issue Aug 20, 2021
Reduce the steps in running restful-react by generating the OpenAPI doc and running the converter as part of the build separately. As a result, the script doesn't have to be built by Parcel.

This change also ensures that the file is built and shared with the host correctly when running the development environment.

Refs #399
@thewilkybarkid
Copy link
Member Author

Usage of the ORM currently has a lot of circular dependencies (where two entities depend on each other). The JS changes in Parcel seem to fail when building: Cannot access 'Community' before initialization

@thewilkybarkid
Copy link
Member Author

parcel-bundler/parcel#6694 might help.

@thewilkybarkid
Copy link
Member Author

thewilkybarkid commented Oct 12, 2021

Seems like parcel-bundler/parcel#7053 has fixed one of the main problems (variables declared in the wrong order). It almost compiles now, but there's one enum that becomes misnamed (extracting it into its own module gets around the problem). parcel-bundler/parcel#7057 might be the fix for this (I'm not sure what the PR does, but the test case involves enums.).

@thewilkybarkid thewilkybarkid changed the title Update Parcel to rc.0 Update Parcel to a stable release Oct 21, 2021
@thewilkybarkid
Copy link
Member Author

Parcel 2.0.0 has now been released, but the app still doesn't build.

thewilkybarkid added a commit that referenced this issue Oct 21, 2021
The generated data fixtures in the dev environment aren't helpful as they're not realistic. But worse, there are quite a few problems in this area:

- It fails to run roughly half the time.
- The forked dependency is blocking npm updates.
- The ORM overall is blocking Parcel updates.

Rather than trying to resolve all the issues, this change removes the fixture generation entirely. As a result, the codebase is a fraction simpler.

Refs #399, #406, #421
@thewilkybarkid
Copy link
Member Author

I've tried no end of combinations, but I can't just get it to work, and there's so many tools using magic I can't understand what's going on properly.

When using @parcel/transformer-typescript-tsc things seem to be generated in the wrong order ("Cannot access ... before initialization"). When not, metadata to do with the ORM entity decorators seem to be missing. When adding in Babel configuration to try and sort that out, it's generated in the wrong order again. 🤷‍♂️

@thewilkybarkid
Copy link
Member Author

Trying to resolve the order issue in parcel-bundler/parcel#6676 (comment).

@thewilkybarkid
Copy link
Member Author

I've managed to reproduce the Parcel problem and open a PR: parcel-bundler/parcel#7293.

@thewilkybarkid
Copy link
Member Author

In order to move this forward, we should remove the decorators and use EntitySchema instead.

#398 (comment) needs to be addressed though, as there is some code reliant on the use of decorators.

thewilkybarkid added a commit that referenced this issue Nov 24, 2021
Rather than misusing a private decorator-specific API, this change uses the ORM's metadata storage instead.

A slight issue here is that accessing the entity manager from a repository is technically not a public API, but the code doing so isn't (yet) TypeScript and needs a lot of work anyway.

Refs #398, #399
@thewilkybarkid
Copy link
Member Author

I'm currently struggling to get EntitySchema to work with Parcel's scope hoisting as classes are renamed, whereas the ORM relies on them being unchanged (so they're different at runtime). This wasn't a problem with the decorators as they were processed by TSC before Parcel would try to change them(?). Options are probably either to disable Parcel's scope hoisting/optimisation or define them explicitly.

@thewilkybarkid
Copy link
Member Author

thewilkybarkid commented Nov 25, 2021

define them explicitly

This didn't work, the types seemingly allow for both a class and a name to be set, but the latter is ignored and the name of the class itself continues to be used.

I also looked at using types rather than classes, which works but you have to declare types everywhere (since you're just referring to them by a string).

Feels like the most pragmatic approach now is to stop Parcel from mangling the names.

thewilkybarkid added a commit that referenced this issue Nov 25, 2021
Rather than (inconsistently) using Parcel options in switches, this change places them in the target itself. As a result, they are now consistently applied.

Refs #399
thewilkybarkid added a commit that referenced this issue Nov 25, 2021
Decorators are an experimental feature in TypeScript, which is known to have issues. Changes in Parcel means that it can no longer build the app, so their use is blocking updating Parcel to a stable release.

This change removes the ORM decorators in favour of defining entities programmatically. I'm hoping that the tests and migration-creating script are enough to have caught any mistakes, but given that areas of the app remain untested, it's hard to be sure.

Also, this change has to disable Parcel's scope hoisting, as it renames the entity classes. The rename wasn't a problem when using decorators as the generated code saw the class name left unchanged. Now, however, the ORM breaks if they are changed.

Refs #399, parcel-bundler/parcel#7293 (comment), microsoft/TypeScript#27519
thewilkybarkid added a commit that referenced this issue Nov 26, 2021
thewilkybarkid added a commit that referenced this issue Nov 26, 2021
thewilkybarkid added a commit that referenced this issue Nov 29, 2021
This change builds all the scripts in one go, which seems to be faster but also reduces the complexity of running them (since TypeScript is no longer needed).

Refs #390, #399
thewilkybarkid added a commit that referenced this issue Nov 29, 2021
Now that decorators are no longer used, we can use Parcel's built-in mechanism for compiling TypeScript. Parcel uses SWC (https://swc.rs/) rather than tsc.

Refs #399, e66f0d8
@KillerCodeMonkey
Copy link

hey gordon shumway :D. (nice avatar)

i saw your issues at parcel to use parcel v2.

I am using typeorm with sqlite in an electron app.
everything worked with parcel v2 beta3.1 but not with the final version.

I got it working by:

  • deactivating scopeHoisting and optimizations.
  • to avoid circular deps in entities - import you entities as with "type" and use relations as strings, e.g.
import type { person } from '../entities/person'

@Entity({ name: 'family' })
export class Family {
  @PrimaryGeneratedColumn()
  id: number

  // One family holds multiple patients
  @OneToMany('Person', 'family', { eager: true })
  patients: Person[]

  @CreateDateColumn()
  createdAt: Date

  @UpdateDateColumn()
  updatedAt: Date
}

PS: in the beta i needed to set a specific entity name, because parcels scopeHosting transformed the name of the class.

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

No branches or pull requests

2 participants