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

add support for string module ids #51

Merged
merged 1 commit into from
May 18, 2017
Merged

Conversation

jbellenger
Copy link
Collaborator

ProductionModePlugin writes module ids as unescaped values. This works for the most common case of integer module ids, but not for strings. Trying to use ProductionModePlugin with something like NamedModulesPlugin, renders the snippet below which throws a syntax error at runtime:

module.exports = factory( __webpack_require__(./node_modules/globalize/dist/globalize-runtime/number.js), __webpack_require__(./node_modules/globalize/dist/globalize-runtime/plural.js), __webpack_require__(./node_modules/globalize/dist/globalize-runtime/message.js), __webpack_require__(./node_modules/globalize/dist/globalize-runtime/currency.js), __webpack_require__(./node_modules/globalize/dist/globalize-runtime/date.js), __webpack_require__(./node_modules/globalize/dist/globalize-runtime/relative-time.js), __webpack_require__(./node_modules/globalize/dist/globalize-runtime/unit.js) );

This PR adds support for quoting module ids that look like strings.

@rxaviers
Copy link
Owner

rxaviers commented May 8, 2017

Any unit test we could add?

@jbellenger
Copy link
Collaborator Author

Totally, though I think it might require bumping the webpack devDep to webpack2. Does that work?

@rxaviers
Copy link
Owner

rxaviers commented May 9, 2017

Sure, go for it... Any suggestions how we could test for various webpack versions? One approach would be splitting the plugin development into webpack-1 and webpack-2 separate branches...

@jbellenger
Copy link
Collaborator Author

I'll update the PR to include a webpack2 upgrade.
As far as supporting different webpack versions, for simplicity sake I'd just bump the version to 0.4.0 and drop support for webpack1. I'm happy to include that in this PR if that works for you.

@jbellenger
Copy link
Collaborator Author

jbellenger commented May 9, 2017

Updated the diff to include tests for hashed and named module ids. While I was in there, I added linting for tests and moved the test output directory to allow running mocha with --watch

Example test output:

jbellenger !1008 14:36> npm run test                                                                                                                                                                                                                                                                                                                                                                
> globalize-webpack-plugin@0.3.13 test /Users/jbellenger/workspace/globalize-webpack-plugin
> eslint *js test && mocha test
  Globalize Webpack Plugin
    Production Mode
      when using default module ids
        ✓ should extract formatters and parsers from basic code
        The compiled bundle
          ✓ should include formatDate
          ✓ should include formatNumber
          ✓ should include formatCurrency
          ✓ should include formatMessage
          ✓ should include formatRelativeTime
          ✓ should include formatUnit
          ✓ should include parseNumber
          ✓ should include parseDate
      when using named module ids
        ✓ should extract formatters and parsers from basic code
        The compiled bundle
          ✓ should include formatDate
          ✓ should include formatNumber
          ✓ should include formatCurrency
          ✓ should include formatMessage
          ✓ should include formatRelativeTime
          ✓ should include formatUnit
          ✓ should include parseNumber
          ✓ should include parseDate
      when using hashed module ids
        ✓ should extract formatters and parsers from basic code
        The compiled bundle
          ✓ should include formatDate
          ✓ should include formatNumber
          ✓ should include formatCurrency
          ✓ should include formatMessage
          ✓ should include formatRelativeTime
          ✓ should include formatUnit
          ✓ should include parseNumber
          ✓ should include parseDate


  27 passing (1s)

Example test failure when special handling of string module ids is removed:

  1) Globalize Webpack Plugin Production Mode when using named module ids The compiled bundle "before all" hook for "should extract formatters and parsers from basic code":
     /Users/jbellenger/workspace/globalize-webpack-plugin/_test-output/named/en.js:15
		module.exports = factory( __webpack_require__(./node_modules/globalize/dist/globalize-runtime/number.js), __webpack_require__(./node_modules/globalize/dist/globalize-runtime/plural.js), __webpack_require__(./node_modules/globalize/dist/globalize-runtime/message.js), __webpack_require__(./node_modules/globalize/dist/globalize-runtime/currency.js), __webpack_require__(./node_modules/globalize/dist/globalize-runtime/date.js), __webpack_require__(./node_modules/globalize/dist/globalize-runtime/relative-time.js), __webpack_require__(./node_modules/globalize/dist/globalize-runtime/unit.js) );
		                                              ^
SyntaxError: Unexpected token .
      at createScript (vm.js:56:10)
      at Object.runInThisContext (vm.js:97:10)
      at require (internal/module.js:20:19)
      at Context.<anonymous> (test/ProductionModePlugin.js:106:13)

@necolas
Copy link

necolas commented May 13, 2017

for simplicity sake I'd just bump the version to 0.4.0 and drop support for webpack1

SGTM too. The webpack globalize tools could commit to updating to webpack@2 (now at 2.5+) and drop webpack@1 altogether. It would simplify development and help move consumers of these packages onto the latest tools

Signed-off-by: James Bellenger <jbellenger@twitter.com>
@rxaviers rxaviers merged commit 3380b5c into rxaviers:master May 18, 2017
@rxaviers
Copy link
Owner

Thank you!!

@rxaviers
Copy link
Owner

Released 1.0.0-alpha.0 pre-release (webpack-2 only support).

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