package init

This commit is contained in:
wang_yue111 2020-08-20 11:20:04 +08:00
parent 7d218ebfff
commit bf197d9d95
4 changed files with 84 additions and 0 deletions

49
nodejs-resolve-from.spec Normal file
View File

@ -0,0 +1,49 @@
%global enable_tests 0
%global module_name resolve-from
Name: nodejs-%{module_name}
Version: 4.0.0
Release: 1
Summary: Resolve the path of a module like require.resolve() but from a given path
License: MIT
URL: https://github.com/sindresorhus/resolve-from
Source0: http://registry.npmjs.org/resolve-from/-/resolve-from-%{version}.tgz
Source1: https://raw.githubusercontent.com/sindresorhus/resolve-from/v%{version}/test.js
BuildArch: noarch
ExclusiveArch: %{nodejs_arches} noarch
BuildRequires: nodejs-packaging
%if 0%{?enable_tests}
BuildRequires: npm(ava)
%endif
%description
%{summary}.
%prep
%autosetup -n package
rm -rf node_modules
cp -p %{SOURCE1} .
%build
%install
mkdir -p %{buildroot}%{nodejs_sitelib}/%{module_name}
cp -pr package.json *.js %{buildroot}%{nodejs_sitelib}/%{module_name}
%nodejs_symlink_deps
%check
%nodejs_symlink_deps --check
%{__nodejs} -e 'require("./")'
%if 0%{?enable_tests}
node test.js
%else
%{_bindir}/echo -e "\e[101m -=#=- Tests disabled -=#=- \e[0m"
%endif
%files
%{!?_licensedir:%global license %doc}
%doc readme.md
%license license
%{nodejs_sitelib}/%{module_name}
%changelog
* Fri Aug 14 2020 wangyue <wangyue92@huawei.com> - 4.0.0-1
- Package init

5
nodejs-resolve-from.yaml Normal file
View File

@ -0,0 +1,5 @@
git_url: https://github.com/sindresorhus/resolve-from
version_control: github
src_repo: sindresorhus/resolve-from
tag_prefix: "^v"
seperator: "."

BIN
resolve-from-4.0.0.tgz Normal file

Binary file not shown.

30
test.js Normal file
View File

@ -0,0 +1,30 @@
import test from 'ava';
import m from '.';
test('resolveFrom()', t => {
t.throws(() => m(1, './fixture'), /got `number`/);
t.throws(() => m('fixture'), /got `undefined`/);
t.regex(m('fixture', './fixture'), /fixture\/fixture\.js$/);
const moduleNotFoundError = t.throws(() => {
m('fixture', './nonexistent');
}, Error);
t.is(moduleNotFoundError.code, 'MODULE_NOT_FOUND');
t.is(moduleNotFoundError.message, 'Cannot find module \'./nonexistent\'');
const resolveFromfixture = m.bind(null, 'fixture');
t.regex(resolveFromfixture('./fixture'), /fixture\/fixture\.js$/);
t.truthy(m('./fixture/fixture-for-symlinks/symlink-target', 'foo'));
});
test('resolveFrom.silent()', t => {
t.regex(m.silent('fixture', './fixture'), /fixture\/fixture\.js$/);
t.is(m.silent('fixture', './nonexistent'), null);
const silentResolveFromfixture = m.silent.bind(null, 'fixture');
t.regex(silentResolveFromfixture('./fixture'), /fixture\/fixture\.js$/);
t.is(m.silent('fixture-not-exists', './fixture'), null);
});