-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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: let TypeScript do resource copying #1824
Conversation
c354efd
to
d15857c
Compare
@@ -326,7 +326,7 @@ context. | |||
```ts | |||
import {inject} from '@loopback/core'; | |||
import {juggler, AnyObject} from '@loopback/repository'; | |||
const config = require('./redis.datasource.json'); | |||
import * as config from './redis.datasource.json'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to use TS import for json files.
@@ -211,13 +211,14 @@ describe('HttpServer (integration)', () => { | |||
host?: string; | |||
}): HttpServer { | |||
const options: HttpServerOptions = {protocol: 'https', host}; | |||
const certDir = path.resolve(__dirname, '../../../fixtures'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what annoys me.The directory structure is different between source code and the distribution. In this case, developers can be confused as they might assume ../../../fixtures
resolve to packages/fixtures
based on the source code directory chain.
IMO, we must fix this confusion in #1636 to make sure the relative path to project level files such as package.json
or fixtures
stays the same between source code and distribution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming https://github.com/strongloop/loopback-next/pull/1824/files#r223392203 can be addressed in follow-up PRs, I approve this one.
Cross-posting the discussion we had elsewhere.
Yes, I agree this is annoying.
I still would like to give a try to the alternative ts-project-layout approach I have described in #1636 (comment) - let If we decide to follow your approach where So either way we choose, the problem of confusing relative paths can be addressed as part of project-references refactor. |
Enable TypeScript feature "resolveJsonModule" to load datasource configurations in a type-safe way using regular "import" statements.
Move test fixtures from `/test` to package root directories. This way the build step does not have to copy them over to `/dist`, which saves time and will make the watch mode more effective once we enable it.
Rework `lb-tsc` to NOT copy resources by default. Drop `--ignore-resources` flag (which implied that resources are copied by default). Add a new flag `--copy-resources` to allow old projects to request the old behavior.
d15857c
to
034151f
Compare
👍 for |
The first commit enables TypeScript flag
resolveJsonModule
and leverages this feature to load datasource configurations in a type-safe way using regular "import" statements. As a result, the TypeScript compiler is taking care of copying datasource JSON files todist
now.The second commit reorganizes test fixtures so that the build step no longer needs to copy resources to
dist
.The third commit renames
lb-tsc
flag--ignore-resources
to--copy-resources
, changing the behavior oflb-tsc
from "copy by default" to "copy only if asked to". This is a breaking change affecting existing LB4 projects. After this change is published, new projects are going to be scaffolded in such way that they don't need resource copying.I have two goals in mind:
Checklist
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated