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

use esm for requiring default and deprecated features #18218

Closed
wants to merge 13 commits into from
Closed

use esm for requiring default and deprecated features #18218

wants to merge 13 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Jul 24, 2019

See emberjs/data#6231 (comment) for
the motivation.

yarn test blows up locally, which might be related to not properly typing the import of default-features.js or not correctly exporting it in @ember/canary-features.

@rwjblue if you have free moments to give me pointers / review here that would be great.

ts.ScriptTarget.ES2017,
/*setParentNodes */ true
const { default: features } = requireEsm(
'../packages/@ember/canary-features/default-features.js'
Copy link
Author

Choose a reason for hiding this comment

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

I could not use @ember/canary-features/default-features.js for the path. Would this be because ember.js' internal package structure differs from ember data?

Copy link
Member

Choose a reason for hiding this comment

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

I think the local require (e.g. starting with ../packages/) is totally correct here.

@@ -1,35 +1,12 @@
'use strict';

const fs = require('fs');
const ts = require('./typescript');
Copy link
Author

Choose a reason for hiding this comment

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

I see the deprecated features also relies upon this module; I can remove it and merge the deprecated features functionality with this new approach once I sort how the typescript particulars below.

Copy link
Member

Choose a reason for hiding this comment

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

Ya, sounds good to me.

Copy link
Member

rwjblue commented Jul 24, 2019

Thanks for working on this @efx!

packages/@ember/canary-features/index.ts Outdated Show resolved Hide resolved
ts.ScriptTarget.ES2017,
/*setParentNodes */ true
const { default: features } = requireEsm(
'../packages/@ember/canary-features/default-features.js'
Copy link
Member

Choose a reason for hiding this comment

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

I think the local require (e.g. starting with ../packages/) is totally correct here.

@ghost
Copy link
Author

ghost commented Jul 25, 2019

I've updated the type but it still complains about exporting an interface instead of a value
Screen Shot 2019-07-25 at 13 44 46

@ghost ghost changed the title [WIP] attempt to use esm for requiring features attempt to use esm for requiring features Jul 26, 2019
@ghost ghost changed the title attempt to use esm for requiring features use esm for requiring default and deprecated features Jul 26, 2019
@rwjblue
Copy link
Member

rwjblue commented Aug 2, 2019

Currently some linting failures
packages/@ember/-internals/environment/lib/env.ts:1:10 - error TS2305: Module '"../../../deprecated-features"' has no exported member 'FUNCTION_PROTOTYPE_EXTENSIONS'.
304
3051 import { FUNCTION_PROTOTYPE_EXTENSIONS } from '@ember/deprecated-features';
306           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
307
308packages/@ember/-internals/glimmer/lib/utils/custom-component-manager.ts:3:10 - error TS2305: Module '"../../../../deprecated-features"' has no exported member 'COMPONENT_MANAGER_STRING_LOOKUP'.
309
3103 import { COMPONENT_MANAGER_STRING_LOOKUP } from '@ember/deprecated-features';
311           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
312
313packages/@ember/-internals/metal/lib/mixin.ts:18:10 - error TS2305: Module '"../../../deprecated-features"' has no exported member 'ALIAS_METHOD'.
314
31518 import { ALIAS_METHOD } from '@ember/deprecated-features';
316            ~~~~~~~~~~~~
317
318packages/@ember/-internals/routing/lib/system/route.ts:23:10 - error TS2305: Module '"../../../../deprecated-features"' has no exported member 'ROUTER_EVENTS'.
319
32023 import { ROUTER_EVENTS } from '@ember/deprecated-features';
321            ~~~~~~~~~~~~~
322
323packages/@ember/-internals/routing/lib/system/router.ts:5:10 - error TS2305: Module '"../../../../deprecated-features"' has no exported member 'APP_CTRL_ROUTER_PROPS'.
324
3255 import { APP_CTRL_ROUTER_PROPS, ROUTER_EVENTS } from '@ember/deprecated-features';
326           ~~~~~~~~~~~~~~~~~~~~~
327
328packages/@ember/-internals/routing/lib/system/router.ts:5:33 - error TS2305: Module '"../../../../deprecated-features"' has no exported member 'ROUTER_EVENTS'.
329
3305 import { APP_CTRL_ROUTER_PROPS, ROUTER_EVENTS } from '@ember/deprecated-features';
331                                  ~~~~~~~~~~~~~
332
333packages/@ember/polyfills/index.ts:1:10 - error TS2305: Module '"../deprecated-features"' has no exported member 'MERGE'.
334
3351 import { MERGE } from '@ember/deprecated-features';
336           ~~~~~
337
338packages/ember-template-compiler/lib/plugins/deprecate-send-action.ts:3:10 - error TS2305: Module '"../../../@ember/deprecated-features"' has no exported member 'SEND_ACTION'.
339
3403 import { SEND_ACTION } from '@ember/deprecated-features';
341           ~~~~~~~~~~~
342
343packages/ember-template-compiler/lib/plugins/index.ts:23:10 - error TS2305: Module '"../../../@ember/deprecated-features"' has no exported member 'SEND_ACTION'.
344
34523 import { SEND_ACTION } from '@ember/deprecated-features';
346            ~~~~~~~~~~~
347
348
349Found 9 errors.

And some legit errors in the test run, e.g.:

this._paramsFor is not a function

@ghost
Copy link
Author

ghost commented Aug 2, 2019

Hmm, I thought my reexport was working but clearly it does not. Not sure about the exact syntax to export those const declarations from the index.ts so I can avoid repeating what is in index.js. I'll try to finish that later today or this weekend.

*I know not typescript*
This makes it work but now there are 2 copies of these flags in
`index.js` and `index.ts`. I am pushing up to avoid blocking and we can
consider a follow up PR or any intervening TS guidance to solve the
duplication.
@ghost
Copy link
Author

ghost commented Sep 4, 2019

Closing this as I've run out of steam. I might come back to it once I actually learn TS. May need to spike and try ts-node as esm doesn't interoperate directly with TS.

@ghost ghost closed this Sep 4, 2019
This pull request was closed.
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.

3 participants