| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ const { | |||
| 36 | 36 | rekeySourceMap | |
| 37 | 37 | } = require('internal/source_map/source_map_cache'); | |
| 38 | 38 | const { pathToFileURL, fileURLToPath, URL } = require('internal/url'); | |
| 39 | - const { deprecate } = require('internal/util'); | ||
| 39 | + const { deprecate, emitExperimentalWarning } = require('internal/util'); | ||
| 40 | 40 | const vm = require('vm'); | |
| 41 | 41 | const assert = require('internal/assert'); | |
| 42 | 42 | const fs = require('fs'); | |
@@ -576,17 +576,21 @@ function resolveExportsTarget(pkgPath, target, subpath, basePath, mappingKey) { | |||
| 576 | 576 | if (experimentalConditionalExports && | |
| 577 | 577 | ObjectPrototype.hasOwnProperty(target, 'require')) { | |
| 578 | 578 | try { | |
| 579 | - return resolveExportsTarget(pkgPath, target.require, subpath, | ||
| 580 | - basePath, mappingKey); | ||
| 579 | + const result = resolveExportsTarget(pkgPath, target.require, subpath, | ||
| 580 | + basePath, mappingKey); | ||
| 581 | + emitExperimentalWarning('Conditional exports'); | ||
| 582 | + return result; | ||
| 581 | 583 | } catch (e) { | |
| 582 | 584 | if (e.code !== 'MODULE_NOT_FOUND') throw e; | |
| 583 | 585 | } | |
| 584 | 586 | } | |
| 585 | 587 | if (experimentalConditionalExports && | |
| 586 | 588 | ObjectPrototype.hasOwnProperty(target, 'node')) { | |
| 587 | 589 | try { | |
| 588 | - return resolveExportsTarget(pkgPath, target.node, subpath, | ||
| 589 | - basePath, mappingKey); | ||
| 590 | + const result = resolveExportsTarget(pkgPath, target.node, subpath, | ||
| 591 | + basePath, mappingKey); | ||
| 592 | + emitExperimentalWarning('Conditional exports'); | ||
| 593 | + return result; | ||
| 590 | 594 | } catch (e) { | |
| 591 | 595 | if (e.code !== 'MODULE_NOT_FOUND') throw e; | |
| 592 | 596 | } | |
@@ -689,6 +693,7 @@ Module._findPath = function(request, paths, isMain) { | |||
| 689 | 693 | ||
| 690 | 694 | const selfFilename = trySelf(paths, exts, isMain, trailingSlash, request); | |
| 691 | 695 | if (selfFilename) { | |
| 696 | + emitExperimentalWarning('Package name self resolution'); | ||
| 692 | 697 | Module._pathCache[cacheKey] = selfFilename; | |
| 693 | 698 | return selfFilename; | |
| 694 | 699 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,7 @@ const createDynamicModule = require( | |||
| 22 | 22 | const fs = require('fs'); | |
| 23 | 23 | const { fileURLToPath, URL } = require('url'); | |
| 24 | 24 | const { debuglog } = require('internal/util/debuglog'); | |
| 25 | - const { promisify } = require('internal/util'); | ||
| 25 | + const { promisify, emitExperimentalWarning } = require('internal/util'); | ||
| 26 | 26 | const { | |
| 27 | 27 | ERR_INVALID_URL, | |
| 28 | 28 | ERR_INVALID_URL_SCHEME, | |
@@ -134,6 +134,7 @@ translators.set('builtin', async function builtinStrategy(url) { | |||
| 134 | 134 | ||
| 135 | 135 | // Strategy for loading a JSON file | |
| 136 | 136 | translators.set('json', async function jsonStrategy(url) { | |
| 137 | + emitExperimentalWarning('Importing JSON modules'); | ||
| 137 | 138 | debug(`Translating JSONModule ${url}`); | |
| 138 | 139 | debug(`Loading JSONModule ${url}`); | |
| 139 | 140 | const pathname = url.startsWith('file:') ? fileURLToPath(url) : null; | |
@@ -188,6 +189,7 @@ translators.set('json', async function jsonStrategy(url) { | |||
| 188 | 189 | ||
| 189 | 190 | // Strategy for loading a wasm module | |
| 190 | 191 | translators.set('wasm', async function(url) { | |
| 192 | + emitExperimentalWarning('Importing Web Assembly modules'); | ||
| 191 | 193 | const buffer = await getSource(url); | |
| 192 | 194 | debug(`Translating WASMModule ${url}`); | |
| 193 | 195 | let compiled; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,7 @@ | |||
| 7 | 7 | #include "util-inl.h" | |
| 8 | 8 | #include "node_contextify.h" | |
| 9 | 9 | #include "node_watchdog.h" | |
| 10 | + #include "node_process.h" | ||
| 10 | 11 | ||
| 11 | 12 | #include <sys/stat.h> // S_IFDIR | |
| 12 | 13 | ||
@@ -962,6 +963,7 @@ Maybe<URL> ResolveExportsTarget(Environment* env, | |||
| 962 | 963 | Maybe<URL> resolved = ResolveExportsTarget(env, pjson_url, | |
| 963 | 964 | conditionalTarget, subpath, pkg_subpath, base, false); | |
| 964 | 965 | if (!resolved.IsNothing()) { | |
| 966 | + ProcessEmitExperimentalWarning(env, "Conditional exports"); | ||
| 965 | 967 | return resolved; | |
| 966 | 968 | } | |
| 967 | 969 | } | |
@@ -1267,6 +1269,7 @@ Maybe<URL> PackageResolve(Environment* env, | |||
| 1267 | 1269 | ||
| 1268 | 1270 | Maybe<URL> self_url = ResolveSelf(env, specifier, base); | |
| 1269 | 1271 | if (self_url.IsJust()) { | |
| 1272 | + ProcessEmitExperimentalWarning(env, "Package name self resolution"); | ||
| 1270 | 1273 | return self_url; | |
| 1271 | 1274 | } | |
| 1272 | 1275 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,6 +27,8 @@ v8::Maybe<bool> ProcessEmitWarningGeneric(Environment* env, | |||
| 27 | 27 | const char* code = nullptr); | |
| 28 | 28 | ||
| 29 | 29 | v8::Maybe<bool> ProcessEmitWarning(Environment* env, const char* fmt, ...); | |
| 30 | + v8::Maybe<bool> ProcessEmitExperimentalWarning(Environment* env, | ||
| 31 | + const char* warning); | ||
| 30 | 32 | v8::Maybe<bool> ProcessEmitDeprecationWarning(Environment* env, | |
| 31 | 33 | const char* warning, | |
| 32 | 34 | const char* deprecation_code); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | #include <cstdarg> | |
| 2 | + #include <set> | ||
| 2 | 3 | ||
| 3 | 4 | #include "env-inl.h" | |
| 4 | 5 | #include "node_process.h" | |
@@ -93,6 +94,21 @@ Maybe<bool> ProcessEmitWarning(Environment* env, const char* fmt, ...) { | |||
| 93 | 94 | return ProcessEmitWarningGeneric(env, warning); | |
| 94 | 95 | } | |
| 95 | 96 | ||
| 97 | + | ||
| 98 | + std::set<std::string> experimental_warnings; | ||
| 99 | + | ||
| 100 | + Maybe<bool> ProcessEmitExperimentalWarning(Environment* env, | ||
| 101 | + const char* warning) { | ||
| 102 | + if (experimental_warnings.find(warning) != experimental_warnings.end()) | ||
| 103 | + return Nothing<bool>(); | ||
| 104 | + | ||
| 105 | + experimental_warnings.insert(warning); | ||
| 106 | + std::string message(warning); | ||
| 107 | + message.append( | ||
| 108 | + " is an experimental feature. This feature could change at any time"); | ||
| 109 | + return ProcessEmitWarningGeneric(env, message.c_str(), "ExperimentalWarning"); | ||
| 110 | + } | ||
| 111 | + | ||
| 96 | 112 | Maybe<bool> ProcessEmitDeprecationWarning(Environment* env, | |
| 97 | 113 | const char* warning, | |
| 98 | 114 | const char* deprecation_code) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,16 @@ | |||
| 1 | + /* eslint-disable node-core/require-common-first, node-core/required-modules */ | ||
| 2 | + import fixtures from './fixtures.js'; | ||
| 3 | + | ||
| 4 | + const { | ||
| 5 | + fixturesDir, | ||
| 6 | + path, | ||
| 7 | + readSync, | ||
| 8 | + readKey, | ||
| 9 | + } = fixtures; | ||
| 10 | + | ||
| 11 | + export { | ||
| 12 | + fixturesDir, | ||
| 13 | + path, | ||
| 14 | + readSync, | ||
| 15 | + readKey, | ||
| 16 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,9 @@ | |||
| 1 | 1 | // Flags: --experimental-modules --experimental-resolve-self --experimental-conditional-exports | |
| 2 | 2 | ||
| 3 | 3 | import { mustCall } from '../common/index.mjs'; | |
| 4 | + import { path } from '../common/fixtures.mjs'; | ||
| 4 | 5 | import { ok, deepStrictEqual, strictEqual } from 'assert'; | |
| 6 | + import { spawn } from 'child_process'; | ||
| 5 | 7 | ||
| 6 | 8 | import { requireFixture, importFixture } from '../fixtures/pkgexports.mjs'; | |
| 7 | 9 | import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js'; | |
@@ -150,3 +152,37 @@ function assertIncludes(actual, expected) { | |||
| 150 | 152 | ok(actual.toString().indexOf(expected) !== -1, | |
| 151 | 153 | `${JSON.stringify(actual)} includes ${JSON.stringify(expected)}`); | |
| 152 | 154 | } | |
| 155 | + | ||
| 156 | + // Test warning message | ||
| 157 | + [ | ||
| 158 | + [ | ||
| 159 | + '--experimental-conditional-exports', | ||
| 160 | + '/es-modules/conditional-exports.js', | ||
| 161 | + 'Conditional exports', | ||
| 162 | + ], | ||
| 163 | + [ | ||
| 164 | + '--experimental-resolve-self', | ||
| 165 | + '/node_modules/pkgexports/resolve-self.js', | ||
| 166 | + 'Package name self resolution', | ||
| 167 | + ], | ||
| 168 | + ].forEach(([flag, file, message]) => { | ||
| 169 | + const child = spawn(process.execPath, [ | ||
| 170 | + '--experimental-modules', | ||
| 171 | + flag, | ||
| 172 | + path(file) | ||
| 173 | + ]); | ||
| 174 | + | ||
| 175 | + let stderr = ''; | ||
| 176 | + child.stderr.setEncoding('utf8'); | ||
| 177 | + child.stderr.on('data', (data) => { | ||
| 178 | + stderr += data; | ||
| 179 | + }); | ||
| 180 | + child.on('close', (code, signal) => { | ||
| 181 | + strictEqual(code, 0); | ||
| 182 | + strictEqual(signal, null); | ||
| 183 | + ok(stderr.toString().includes( | ||
| 184 | + `ExperimentalWarning: ${message} is an experimental feature. ` + | ||
| 185 | + 'This feature could change at any time' | ||
| 186 | + )); | ||
| 187 | + }); | ||
| 188 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,30 @@ | |||
| 1 | 1 | // Flags: --experimental-modules --experimental-json-modules | |
| 2 | 2 | import '../common/index.mjs'; | |
| 3 | - import { strictEqual } from 'assert'; | ||
| 3 | + import { path } from '../common/fixtures.mjs'; | ||
| 4 | + import { strictEqual, ok } from 'assert'; | ||
| 5 | + import { spawn } from 'child_process'; | ||
| 4 | 6 | ||
| 5 | 7 | import secret from '../fixtures/experimental.json'; | |
| 6 | 8 | ||
| 7 | 9 | strictEqual(secret.ofLife, 42); | |
| 10 | + | ||
| 11 | + // Test warning message | ||
| 12 | + const child = spawn(process.execPath, [ | ||
| 13 | + '--experimental-modules', | ||
| 14 | + '--experimental-json-modules', | ||
| 15 | + path('/es-modules/json-modules.mjs') | ||
| 16 | + ]); | ||
| 17 | + | ||
| 18 | + let stderr = ''; | ||
| 19 | + child.stderr.setEncoding('utf8'); | ||
| 20 | + child.stderr.on('data', (data) => { | ||
| 21 | + stderr += data; | ||
| 22 | + }); | ||
| 23 | + child.on('close', (code, signal) => { | ||
| 24 | + strictEqual(code, 0); | ||
| 25 | + strictEqual(signal, null); | ||
| 26 | + ok(stderr.toString().includes( | ||
| 27 | + 'ExperimentalWarning: Importing JSON modules is an experimental feature. ' + | ||
| 28 | + 'This feature could change at any time' | ||
| 29 | + )); | ||
| 30 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,10 @@ | |||
| 1 | 1 | // Flags: --experimental-modules --experimental-wasm-modules | |
| 2 | 2 | import '../common/index.mjs'; | |
| 3 | + import { path } from '../common/fixtures.mjs'; | ||
| 3 | 4 | import { add, addImported } from '../fixtures/es-modules/simple.wasm'; | |
| 4 | 5 | import { state } from '../fixtures/es-modules/wasm-dep.mjs'; | |
| 5 | - import { strictEqual } from 'assert'; | ||
| 6 | + import { strictEqual, ok } from 'assert'; | ||
| 7 | + import { spawn } from 'child_process'; | ||
| 6 | 8 | ||
| 7 | 9 | strictEqual(state, 'WASM Start Executed'); | |
| 8 | 10 | ||
@@ -13,3 +15,24 @@ strictEqual(addImported(0), 42); | |||
| 13 | 15 | strictEqual(state, 'WASM JS Function Executed'); | |
| 14 | 16 | ||
| 15 | 17 | strictEqual(addImported(1), 43); | |
| 18 | + | ||
| 19 | + // Test warning message | ||
| 20 | + const child = spawn(process.execPath, [ | ||
| 21 | + '--experimental-modules', | ||
| 22 | + '--experimental-wasm-modules', | ||
| 23 | + path('/es-modules/wasm-modules.mjs') | ||
| 24 | + ]); | ||
| 25 | + | ||
| 26 | + let stderr = ''; | ||
| 27 | + child.stderr.setEncoding('utf8'); | ||
| 28 | + child.stderr.on('data', (data) => { | ||
| 29 | + stderr += data; | ||
| 30 | + }); | ||
| 31 | + child.on('close', (code, signal) => { | ||
| 32 | + strictEqual(code, 0); | ||
| 33 | + strictEqual(signal, null); | ||
| 34 | + ok(stderr.toString().includes( | ||
| 35 | + 'ExperimentalWarning: Importing Web Assembly modules is ' + | ||
| 36 | + 'an experimental feature. This feature could change at any time' | ||
| 37 | + )); | ||
| 38 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + require('pkgexports/condition') | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments