Skip to content

Commit caf75ab

Browse files
authored
Fix modular add from custom template (#2190)
* Enhanced `modular add` from template logging * Add to Templates documentation * Fix adding from template not adding all files when "files" filter in package.json is not specified * Added template tests * Force addPackage to require.resolve from the modular root * Refactor addPackage tests to not run yarn and use a separate temp testing space * Refactor createModularTestContext to make it more generic * Reduce test template app to skeleton * Use npm-packlist instead of globby for addPackage * Prevent infinite loop in verifyPackageTree
1 parent b438dcc commit caf75ab

File tree

22 files changed

+1391
-125
lines changed

22 files changed

+1391
-125
lines changed

.changeset/clean-jeans-retire.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'modular-scripts': patch
3+
---
4+
5+
Fixed `modular add` from template not copying all template files when no "files"
6+
field is specified in the package.json - now using npm-packlist for this
7+
Added tests for adding from templates
8+
Refactored addPackage tests to use a temp directory outside the repository and
9+
improve performance by avoiding yarn commands in favour of mocking the behaviour
10+
Added more descriptive log messages when running `modular add` with a local
11+
template
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Test File
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "modular-template-app",
3+
"version": "1.1.0",
4+
"exports": {
5+
"./package.json": "./package.json"
6+
},
7+
"modular": {
8+
"type": "template",
9+
"templateType": "app"
10+
},
11+
"license": "Apache-2.0",
12+
"files": [
13+
"src"
14+
]
15+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as React from 'react';
2+
import logo from './logo.svg';
3+
import './App.css';
4+
5+
function App(): JSX.Element {
6+
return (
7+
<div className="App">
8+
<header className="App-header">
9+
<img src={logo} className="App-logo" alt="logo" />
10+
<p>
11+
Edit <code>src/App.tsx</code> and save to reload.
12+
</p>
13+
<a
14+
className="App-link"
15+
href="https://reactjs.org"
16+
target="_blank"
17+
rel="noopener noreferrer"
18+
>
19+
Learn React
20+
</a>
21+
</header>
22+
</div>
23+
);
24+
}
25+
26+
export default App;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import App from '../App';
4+
5+
test('renders learn react link', () => {
6+
render(<App />);
7+
const linkElement = screen.getByText(/learn react/i);
8+
expect(linkElement).toBeInTheDocument();
9+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Test File
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "modular-template-filter",
3+
"version": "0.0.1",
4+
"exports": {
5+
"./package.json": "./package.json"
6+
},
7+
"modular": {
8+
"type": "template",
9+
"templateType": "app"
10+
},
11+
"files": [
12+
"src"
13+
],
14+
"license": "Apache-2.0"
15+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import add from '../index';
2+
3+
test('it should add two numbers', () => {
4+
expect(add(1, 2)).toEqual(3);
5+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function add(a: number, b: number): number {
2+
return a + b;
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Test File

0 commit comments

Comments
 (0)