Upgrade to Pro — share decks privately, control downloads, hide ads and more …

mjs

 mjs

We are JavaScripters で発表した .mjs の話です。

Yosuke Furukawa

April 24, 2018
Tweet

More Decks by Yosuke Furukawa

Other Decks in Programming

Transcript

  1. Node.js v10 
 Notable Changes • for-await-of in Stream experimental

    support • ESModules experimental support • private/public class fields experimental support • fs/promises
  2. DEMO import fs from 'fs/promises'; import util from 'util'; async

    function main() { try { const content = await fs.readFile(process.argv[2]) console.log(content.toString()) } catch(e) { console.error(e.toString()); } } main();
  3. DEMO const builtins = Module.builtinModules; const URL = url.URL; const

    baseURL = new URL('file://'); baseURL.pathname = `${process.cwd()}/`; export function resolve(specifier, parentModuleURL = baseURL, defaultResolve) { if (builtins.includes(specifier)) { return { url: specifier, format: 'builtin' }; } const resolved = new url.URL(specifier, parentModuleURL); const ext = path.extname(resolved.pathname); return { url: resolved.href, format: 'esm' }; }
  4. DEMO $ node —experimental-modules —loader loader.mjs file.js // file.js
 import

    fs from 'fs'; import util from 'util'; const readFile = util.promisify(fs.readFile); async function main() { try { const content = await readFile(process.argv[2]) console.log(content.toString()) } catch(e) { console.error(e.toString()); } } main();
  5. mode detection on flag `—mode` , package.json see: https://gist.github.com/ceejbot/b49f8789b2ab6b09548ccb72813a1054 


    https://docs.google.com/presentation/d/ 1xK1ana_TIxfAHX33CYVHFnJsV0If_YirLtRBBga9cv0/edit#slide=id.p
  6. You would be better to wait the conclusion, if you

    want to use ES Modules in the future.
  7. )PXEPXFUIJOLFT FTpMFFYUFOTJPOTUPEFUFDU WFSTJPOT // sorry no reference… I cannot find

    link 8FOFFEUPDIBOHFpMFOBNFFYUFOTJPOTUPVQHSBEF UIBUJTOJHIUNBSFʜ